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.4  2007/04/19 06:17:21  csoutheren
00030  *  Fixes for precompiled headers with gcc
00031  *
00032  *  Revision 1.3  2007/01/17 22:27:52  dereksmithies
00033  *  Correctly sends DTMF to remote node. Tidy up string handling.
00034  *
00035  *  Revision 1.2  2005/08/24 04:56:25  dereksmithies
00036  *  Add code from Adrian Sietsma to send FullFrameTexts and FullFrameDtmfs to
00037  *  the remote end.  Many Thanks.
00038  *
00039  *  Revision 1.1  2005/07/30 07:01:32  csoutheren
00040  *  Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
00041  *  Thanks to Derek Smithies of Indranet Technologies Ltd. for
00042  *  writing and contributing this code
00043  *
00044  *
00045  *
00046  *
00047  */
00048 
00049 #ifndef SAFESTRINGS_H
00050 #define SAFESTRINGS_H
00051 
00052 #ifndef _PTLIB_H
00053 #include <ptlib.h>
00054 #endif
00055 
00056 #ifdef P_USE_PRAGMA
00057 #pragma interface
00058 #endif
00059 
00060 
00065 class SafeStrings :  public PObject
00066 {
00067   PCLASSINFO(SafeStrings, PObject);
00068  public:
00073   SafeStrings();
00074   
00076   ~SafeStrings();
00078   
00081   
00083   void AppendString(const PString & newString,        
00084                     PBoolean splitString = PFalse   
00085                     );
00086   
00088   void AppendString(const char *newString,     
00089                     PBoolean splitString = PFalse   
00090                     ) { PString s(newString); AppendString(s, splitString); }
00091   
00093   PBoolean GetNextString(PString & nextString 
00094                      );
00095   
00097   PBoolean IsEmpty();
00098 
00100   PBoolean StringsAvailable() { return !IsEmpty(); }
00101   
00103   PString GetFirstDeleteAll();
00104   
00106   void GetAllDeleteAll(PStringArray & res);
00107   
00109  protected:
00111   PMutex accessMutex;
00112   
00114   PStringArray data;
00115 };
00116 
00118 
00119 class SafeString : public PObject
00120 {
00121   PCLASSINFO(SafeString, PObject);
00122  public:
00124   SafeString() { internal = PString::Empty(); }
00125   
00127   SafeString(PString newValue) { internal = newValue; }
00128   
00130   void operator = (PString newValue);
00131   
00133   PString Get() { PWaitAndSignal m(mutex); return internal; }
00134   
00136   virtual void PrintOn(ostream & str) const;
00137   
00139   operator PString();
00140   
00142   void operator += (PString toBeAdded);
00143 
00145   PString GetAndDelete();
00146 
00148   PBoolean IsEmpty() const;
00149 
00150 
00151  protected:
00153   PString internal;
00154   
00156   PMutex mutex;
00157 };
00158 
00160 
00161 #endif // SAFESTRINGS_H
00162 /* The comment below is magic for those who use emacs to edit this file. */
00163 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00164 
00165 /*
00166  * Local Variables:
00167  * mode:c
00168  * c-file-style:linux
00169  * c-basic-offset:2
00170  * End:
00171  */
00172 

Generated on Mon Sep 15 11:49:15 2008 for OPAL by  doxygen 1.5.1