00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __PRM_STRINGREP_H_INCLUDED__
00020 #define __PRM_STRINGREP_H_INCLUDED__
00021
00022 #include "PRM_API.h"
00023 #include "PRM_Lock.h"
00024 #include <UT/UT_WorkBuffer.h>
00025 #include <SYS/SYS_Types.h>
00026 #include <string.h>
00027
00028
00029
00030
00031 class PRM_API PRM_StringRep
00032 {
00033 public:
00034 PRM_StringRep()
00035 : myData(NULL)
00036 {
00037 }
00038 ~PRM_StringRep()
00039 {
00040 ::free(myData);
00041 }
00042
00043
00044 void get(PRM_SpinLock &lock, UT_WorkBuffer &result);
00045 void get(PRM_SpinLock &lock, UT_String &result);
00046 void harden(PRM_SpinLock &lock, const char *source);
00047 void hardenIfNeeded(
00048 PRM_SpinLock &lock,
00049 const char *source);
00050
00051
00052
00053
00054 const char * unsafeGet() const
00055 { return myData; }
00056 void unsafeHarden(const char *str)
00057 {
00058 ::free(myData);
00059 myData = safeDup(str);
00060 }
00061 void unsafeHarden(const PRM_StringRep &str)
00062 {
00063 ::free(myData);
00064 myData = safeDup(str.unsafeGet());
00065 }
00066
00067 exint getMemoryUsage() const;
00068 bool findString(
00069 const char *str,
00070 bool fullword,
00071 bool usewildcards) const;
00072
00073
00074 private:
00075 static inline char * safeDup(const char *str)
00076 {
00077 if (str != NULL && *str)
00078 return ::strdup(str);
00079 return NULL;
00080 }
00081
00082 char * myData;
00083 };
00084
00085 #endif // __PRM_STRINGREP_H_INCLUDED__