safestrings.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Inter Asterisk Exchange 2
00005  * 
00006  * Provide string list handling in a thread safe fashion.
00007  * 
00008  * Open Phone Abstraction Library (OPAL)
00009  *
00010  * Copyright (c) 2005 Indranet Technologies Ltd.
00011  *
00012  * The contents of this file are subject to the Mozilla Public License
00013  * Version 1.0 (the "License"); you may not use this file except in
00014  * compliance with the License. You may obtain a copy of the License at
00015  * http://www.mozilla.org/MPL/
00016  *
00017  * Software distributed under the License is distributed on an "AS IS"
00018  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00019  * the License for the specific language governing rights and limitations
00020  * under the License.
00021  *
00022  * The Original Code is Open Phone Abstraction Library.
00023  *
00024  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
00025  *
00026  * The author of this code is Derek J Smithies
00027  *
00028  *  $Log: safestrings.h,v $
00029  *  Revision 1.2  2005/08/24 04:56:25  dereksmithies
00030  *  Add code from Adrian Sietsma to send FullFrameTexts and FullFrameDtmfs to
00031  *  the remote end.  Many Thanks.
00032  *
00033  *  Revision 1.1  2005/07/30 07:01:32  csoutheren
00034  *  Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
00035  *  Thanks to Derek Smithies of Indranet Technologies Ltd. for
00036  *  writing and contributing this code
00037  *
00038  *
00039  *
00040  *
00041  */
00042 
00043 #ifndef SAFESTRINGS_H
00044 #define SAFESTRINGS_H
00045 
00046 #include <ptlib.h>
00047 
00048 #ifdef P_USE_PRAGMA
00049 #pragma interface
00050 #endif
00051 
00052 
00057 class SafeStrings :  public PObject
00058 {
00059   PCLASSINFO(SafeStrings, PObject);
00060  public:
00065   SafeStrings();
00066   
00068   ~SafeStrings();
00070   
00073   
00075   void AppendString(PString & newString,        
00076                     BOOL splitString = FALSE   
00077                     );
00078   
00080   void AppendString(const char *newString,     
00081                     BOOL splitString = FALSE   
00082                     ) { PString s(newString); AppendString(s, splitString); }
00083   
00085   BOOL GetNextString(PString & nextString 
00086                      );
00087   
00089   BOOL IsEmpty();
00090   
00092   PString GetFirstDeleteAll();
00093   
00095   void GetAllDeleteAll(PStringArray & res);
00096   
00098  protected:
00100   PMutex accessMutex;
00101   
00103   PStringArray data;
00104 };
00105 
00107 
00108 class SafeString : public PObject
00109 {
00110   PCLASSINFO(SafeString, PObject);
00111  public:
00113   SafeString() { internal = PString::Empty(); }
00114   
00116   SafeString(PString newValue) { internal = newValue; }
00117   
00119   void operator = (PString newValue);
00120   
00122   PString Get() { PWaitAndSignal m(mutex); return internal; }
00123   
00125   virtual void PrintOn(ostream & str) const;
00126   
00128   operator PString();
00129   
00131   void operator += (PString toBeAdded);
00132 
00134   PString GetAndDelete();
00135 
00137   BOOL IsEmpty() const;
00138 
00139 
00140  protected:
00142   PString internal;
00143   
00145   PMutex mutex;
00146 };
00147 
00149 
00150 #endif // SAFESTRINGS_H
00151 /* The comment below is magic for those who use emacs to edit this file. */
00152 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00153 
00154 /*
00155  * Local Variables:
00156  * mode:c
00157  * c-file-style:linux
00158  * c-basic-offset:2
00159  * End:
00160  */
00161 

Generated on Mon Sep 25 16:20:10 2006 for OPAL by  doxygen 1.4.7