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 #include <opal/buildopts.h>
00057 
00058 #ifdef P_USE_PRAGMA
00059 #pragma interface
00060 #endif
00061 
00062 
00067 class SafeStrings :  public PObject
00068 {
00069   PCLASSINFO(SafeStrings, PObject);
00070  public:
00075   SafeStrings();
00076   
00078   ~SafeStrings();
00080   
00083   
00085   void AppendString(const PString & newString,        
00086                     PBoolean splitString = PFalse   
00087                     );
00088   
00090   void AppendString(const char *newString,     
00091                     PBoolean splitString = PFalse   
00092                     ) { PString s(newString); AppendString(s, splitString); }
00093   
00095   PBoolean GetNextString(PString & nextString 
00096                      );
00097   
00099   PBoolean IsEmpty();
00100 
00102   PBoolean StringsAvailable() { return !IsEmpty(); }
00103   
00105   PString GetFirstDeleteAll();
00106   
00108   void GetAllDeleteAll(PStringArray & res);
00109   
00111  protected:
00113   PMutex accessMutex;
00114   
00116   PStringArray data;
00117 };
00118 
00120 
00121 class SafeString : public PObject
00122 {
00123   PCLASSINFO(SafeString, PObject);
00124  public:
00126   SafeString() { internal = PString::Empty(); }
00127   
00129   SafeString(PString newValue) { internal = newValue; }
00130   
00132   void operator = (PString newValue);
00133   
00135   PString Get() { PWaitAndSignal m(mutex); return internal; }
00136   
00138   virtual void PrintOn(ostream & str) const;
00139   
00141   operator PString();
00142   
00144   void operator += (PString toBeAdded);
00145 
00147   PString GetAndDelete();
00148 
00150   PBoolean IsEmpty() const;
00151 
00152 
00153  protected:
00155   PString internal;
00156   
00158   PMutex mutex;
00159 };
00160 
00162 
00163 #endif // SAFESTRINGS_H
00164 /* The comment below is magic for those who use emacs to edit this file. */
00165 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00166 
00167 /*
00168  * Local Variables:
00169  * mode:c
00170  * c-file-style:linux
00171  * c-basic-offset:2
00172  * End:
00173  */
00174 

Generated on Mon Sep 22 12:24:54 2008 for OPAL by  doxygen 1.5.1