HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PRM_StringRep.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: PRM_StringRep.h (PRM Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __PRM_STRINGREP_H_INCLUDED__
12 #define __PRM_STRINGREP_H_INCLUDED__
13 
14 #include "PRM_API.h"
15 #include "PRM_Lock.h"
16 #include <UT/UT_WorkBuffer.h>
17 #include <SYS/SYS_Types.h>
18 #include <string.h>
19 
20 /// A specialized deep string class that implements a special case of hazard
21 /// pointers where only 1 read-lock per thread for *any* PRM_StringRep
22 /// object can be active.
24 {
25 public:
27  : myData(NULL)
28  {
29  }
31  {
32  ::free(myData);
33  }
34  /// Thread-safe accessors
35  // @{
36  void get(PRM_SpinLock &lock, UT_WorkBuffer &result);
37  void get(PRM_SpinLock &lock, UT_String &result);
38  void harden(PRM_SpinLock &lock, const char *source);
39  void hardenIfNeeded(
40  PRM_SpinLock &lock,
41  const char *source);
42  // @}
43 
44  /// Non-thread-safe accessors
45  // @{
46  const char * unsafeGet() const
47  { return myData; }
48  void unsafeHarden(const char *str)
49  {
50  ::free(myData);
51  myData = safeDup(str);
52  }
54  {
55  ::free(myData);
56  myData = str.steal();
57  }
58  void unsafeHarden(const PRM_StringRep &str)
59  {
60  ::free(myData);
61  myData = safeDup(str.unsafeGet());
62  }
63 
64  exint getMemoryUsage() const;
65  bool findString(
66  const char *str,
67  bool fullword,
68  bool usewildcards) const;
69  bool findVariable(const char *str) const;
70  // @}
71 
72 private:
73  static inline char * safeDup(const char *str)
74  {
75  if (str != NULL && *str)
76  return ::strdup(str);
77  return NULL;
78  }
79 
80  char * myData;
81 };
82 
83 #endif // __PRM_STRINGREP_H_INCLUDED__
void unsafeAdopt(UT_String &str)
Non-thread-safe accessors.
Definition: PRM_StringRep.h:53
tbb::spin_rw_mutex PRM_SpinLock
Definition: PRM_Lock.h:22
int64 exint
Definition: SYS_Types.h:115
void unsafeHarden(const PRM_StringRep &str)
Non-thread-safe accessors.
Definition: PRM_StringRep.h:58
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
void unsafeHarden(const char *str)
Non-thread-safe accessors.
Definition: PRM_StringRep.h:48
char * steal(void)
Definition: UT_String.h:253
const char * unsafeGet() const
Non-thread-safe accessors.
Definition: PRM_StringRep.h:46
#define PRM_API
Definition: PRM_API.h:10