OPAL  Version 3.18.8
safestrings.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Inter Asterisk Exchange 2
5  *
6  * Provide string list handling in a thread safe fashion.
7  *
8  * Open Phone Abstraction Library (OPAL)
9  *
10  * Copyright (c) 2005 Indranet Technologies Ltd.
11  *
12  * The contents of this file are subject to the Mozilla Public License
13  * Version 1.0 (the "License"); you may not use this file except in
14  * compliance with the License. You may obtain a copy of the License at
15  * http://www.mozilla.org/MPL/
16  *
17  * Software distributed under the License is distributed on an "AS IS"
18  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19  * the License for the specific language governing rights and limitations
20  * under the License.
21  *
22  * The Original Code is Open Phone Abstraction Library.
23  *
24  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
25  *
26  * The author of this code is Derek J Smithies
27  */
28 
29 #ifndef OPAL_IAX2_SAFESTRINGS_H
30 #define OPAL_IAX2_SAFESTRINGS_H
31 
32 #ifndef _PTLIB_H
33 #include <ptlib.h>
34 #endif
35 
36 #include <opal_config.h>
37 
38 #if OPAL_IAX2
39 
40 #ifdef P_USE_PRAGMA
41 #pragma interface
42 #endif
43 
44 
49 class SafeStrings : public PObject
50 {
51  PCLASSINFO(SafeStrings, PObject);
52  public:
57  SafeStrings();
58 
60  ~SafeStrings();
62 
65 
67  void AppendString(const PString & newString,
68  PBoolean splitString = false
69  );
70 
72  void AppendString(const char *newString,
73  PBoolean splitString = false
74  ) { PString s(newString); AppendString(s, splitString); }
75 
77  PBoolean GetNextString(PString & nextString
78  );
79 
81  PBoolean IsEmpty();
82 
84  PBoolean StringsAvailable() { return !IsEmpty(); }
85 
87  PString GetFirstDeleteAll();
88 
90  void GetAllDeleteAll(PStringArray & res);
91 
93  protected:
95  PDECLARE_MUTEX(accessMutex);
96 
98  PStringArray data;
99 };
100 
102 
103 class SafeString : public PObject
104 {
105  PCLASSINFO(SafeString, PObject);
106  public:
108  SafeString() { internal = PString::Empty(); }
109 
111  SafeString(PString newValue) { internal = newValue; }
112 
114  void operator = (PString newValue);
115 
117  PString Get() { PWaitAndSignal m(mutex); return internal; }
118 
120  virtual void PrintOn(ostream & str) const;
121 
123  operator PString();
124 
126  void operator += (PString toBeAdded);
127 
129  PString GetAndDelete();
130 
132  PBoolean IsEmpty() const;
133 
134 
135  protected:
137  PString internal;
138 
140  PDECLARE_MUTEX(mutex);
141 };
142 
144 
145 
146 #endif // OPAL_IAX2
147 
148 #endif // OPAL_IAX2_SAFESTRINGS_H
149 
150 /* The comment below is magic for those who use emacs to edit this file.
151  * With the comment below, the tab key does auto indent to 2 spaces.
152  *
153  * Local Variables:
154  * mode:c
155  * c-basic-offset:2
156  * End:
157  */
void GetAllDeleteAll(PStringArray &res)
SafeString()
Definition: safestrings.h:108
PDECLARE_MUTEX(accessMutex)
PBoolean IsEmpty()
PString GetAndDelete()
void operator+=(PString toBeAdded)
Definition: safestrings.h:103
void AppendString(const PString &newString, PBoolean splitString=false)
void operator=(PString newValue)
SafeString(PString newValue)
Definition: safestrings.h:111
PString Get()
Definition: safestrings.h:117
PBoolean IsEmpty() const
Definition: safestrings.h:49
PBoolean StringsAvailable()
Definition: safestrings.h:84
PDECLARE_MUTEX(mutex)
void AppendString(const char *newString, PBoolean splitString=false)
Definition: safestrings.h:72
virtual void PrintOn(ostream &str) const
PString GetFirstDeleteAll()
PBoolean GetNextString(PString &nextString)
PStringArray data
Definition: safestrings.h:98