HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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_NonCopyable.h>
17 #include <UT/UT_WorkBuffer.h>
18 #include <SYS/SYS_Types.h>
19 #include <string.h>
20 
21 /// A specialized deep string class that implements a special case of hazard
22 /// pointers where only 1 read-lock per thread for *any* PRM_StringRep
23 /// object can be active.
25 {
26 public:
28  : myData(NULL)
29  {
30  }
32  {
33  ::free(myData);
34  }
35 
37 
38  /// Thread-safe accessors
39  // @{
41  void get(PRM_SpinLock &lock, UT_String &result);
42  void harden(PRM_SpinLock &lock, const char *source);
43  void hardenIfNeeded(
44  PRM_SpinLock &lock,
45  const char *source);
46  // @}
47 
48  /// Non-thread-safe accessors
49  // @{
50  const char * unsafeGet() const
51  { return myData; }
52  void unsafeHarden(const char *str)
53  {
54  ::free(myData);
55  myData = safeDup(str);
56  }
58  {
59  ::free(myData);
60  myData = str.steal();
61  }
62  void unsafeHarden(const PRM_StringRep &str)
63  {
64  ::free(myData);
65  myData = safeDup(str.unsafeGet());
66  }
67 
68  exint getMemoryUsage() const;
69  bool findString(
70  const char *str,
71  bool fullword,
72  bool usewildcards) const;
73  bool findVariable(const char *str) const;
74  // @}
75 
76 private:
77  static inline char * safeDup(const char *str)
78  {
79  if (str != NULL && *str)
80  return ::strdup(str);
81  return NULL;
82  }
83 
84  char * myData;
85 };
86 
87 #endif // __PRM_STRINGREP_H_INCLUDED__
void
Definition: png.h:1083
void unsafeAdopt(UT_String &str)
Non-thread-safe accessors.
Definition: PRM_StringRep.h:57
int64 exint
Definition: SYS_Types.h:125
**But if you need a result
Definition: thread.h:622
tbb::spin_rw_mutex PRM_SpinLock
Definition: PRM_Lock.h:22
void unsafeHarden(const PRM_StringRep &str)
Non-thread-safe accessors.
Definition: PRM_StringRep.h:62
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
Definition: UT_ARTMap.h:1173
void unsafeHarden(const char *str)
Non-thread-safe accessors.
Definition: PRM_StringRep.h:52
const char * unsafeGet() const
Non-thread-safe accessors.
Definition: PRM_StringRep.h:50
char * steal()
Definition: UT_String.h:262
#define PRM_API
Definition: PRM_API.h:10