1 #ifndef _WDL_STRINGPOOL_H_
2 #define _WDL_STRINGPOOL_H_
6 #include "assocarray.h"
11 friend class WDL_PooledString
;
13 WDL_StringPool(bool wantMutex
) : m_strings(true) { m_mutex
= wantMutex
? new WDL_Mutex
: NULL
; };
14 ~WDL_StringPool() { delete m_mutex
; }
17 WDL_StringKeyedArray
<int> m_strings
;
23 class WDL_PooledString
26 WDL_PooledString(WDL_StringPool
*pool
, const char *value
=NULL
) { m_pool
= pool
; m_val
= ""; Set(value
); }
27 ~WDL_PooledString() { Set(""); }
29 const char *Get() { return m_val
; }
31 void Set(const char *value
)
34 if (strcmp(value
,m_val
))
36 WDL_MutexLock(m_pool
->m_mutex
); // may or may not actually be a mutex
38 const char *oldval
= m_val
;
43 const char *keyptr
=NULL
;
44 int * ref
= m_pool
->m_strings
.GetPtr(value
,&keyptr
);
50 else m_pool
->m_strings
.Insert(value
,1,&m_val
);
56 int *oldref
= m_pool
->m_strings
.GetPtr(oldval
);
57 if (oldref
&& --*oldref
<=0) m_pool
->m_strings
.Delete(oldval
);
62 // utility for compat with WDL_String
63 void Append(const char *value
)
67 WDL_String
tmp(Get());
72 void Insert(const char *value
, int pos
)
74 WDL_String
tmp(Get());
75 tmp
.Insert(value
,pos
);
78 void DeleteSub(int pos
, int len
)
80 WDL_String
tmp(Get());
81 tmp
.DeleteSub(pos
,len
);
87 WDL_StringPool
*m_pool
;
92 #endif _WDL_STRINGPOOL_H_