OPAL
Version 3.10.4
|
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 * $Revision: 24606 $ 00029 * $Author: dereksmithies $ 00030 * $Date: 2010-07-28 22:51:05 -0500 (Wed, 28 Jul 2010) $ 00031 */ 00032 00033 #ifndef OPAL_IAX2_SAFESTRINGS_H 00034 #define OPAL_IAX2_SAFESTRINGS_H 00035 00036 #ifndef _PTLIB_H 00037 #include <ptlib.h> 00038 #endif 00039 00040 #include <opal/buildopts.h> 00041 00042 #if OPAL_IAX2 00043 00044 #ifdef P_USE_PRAGMA 00045 #pragma interface 00046 #endif 00047 00048 00053 class SafeStrings : public PObject 00054 { 00055 PCLASSINFO(SafeStrings, PObject); 00056 public: 00061 SafeStrings(); 00062 00064 ~SafeStrings(); 00066 00069 00071 void AppendString(const PString & newString, 00072 PBoolean splitString = false 00073 ); 00074 00076 void AppendString(const char *newString, 00077 PBoolean splitString = false 00078 ) { PString s(newString); AppendString(s, splitString); } 00079 00081 PBoolean GetNextString(PString & nextString 00082 ); 00083 00085 PBoolean IsEmpty(); 00086 00088 PBoolean StringsAvailable() { return !IsEmpty(); } 00089 00091 PString GetFirstDeleteAll(); 00092 00094 void GetAllDeleteAll(PStringArray & res); 00095 00097 protected: 00099 PMutex accessMutex; 00100 00102 PStringArray data; 00103 }; 00104 00106 00107 class SafeString : public PObject 00108 { 00109 PCLASSINFO(SafeString, PObject); 00110 public: 00112 SafeString() { internal = PString::Empty(); } 00113 00115 SafeString(PString newValue) { internal = newValue; } 00116 00118 void operator = (PString newValue); 00119 00121 PString Get() { PWaitAndSignal m(mutex); return internal; } 00122 00124 virtual void PrintOn(ostream & str) const; 00125 00127 operator PString(); 00128 00130 void operator += (PString toBeAdded); 00131 00133 PString GetAndDelete(); 00134 00136 PBoolean IsEmpty() const; 00137 00138 00139 protected: 00141 PString internal; 00142 00144 PMutex mutex; 00145 }; 00146 00148 00149 00150 #endif // OPAL_IAX2 00151 00152 #endif // OPAL_IAX2_SAFESTRINGS_H 00153 00154 /* The comment below is magic for those who use emacs to edit this file. 00155 * With the comment below, the tab key does auto indent to 2 spaces. 00156 * 00157 * Local Variables: 00158 * mode:c 00159 * c-basic-offset:2 00160 * End: 00161 */