HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CMD_SymbolList.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: CMD_SymbolList.h ( CMD Library, C++)
7  *
8  * COMMENTS: Used by aliases and variables. The symbol list contains a
9  * symbol and a value
10  */
11 
12 #ifndef __CMD_SymbolList__
13 #define __CMD_SymbolList__
14 
15 #include "CMD_API.h"
16 #include <UT/UT_Lock.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_String.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_StringHolder.h>
21 #include <UT/UT_SymbolTable.h>
22 #include <SYS/SYS_Compiler.h>
23 #include <utility>
24 
25 class CMD_Alias;
26 class CMD_Manager;
27 
29 {
30 public:
31  CMD_SymbolEntry(const char *name, const char *value, bool export_var=false)
32  : myName(name)
33  , myValue(value)
34  , myDirtyFlag(true)
35  , myExportFlag(export_var)
36  {
37  if (myExportFlag)
38  exportSymbol();
39  }
41  {
42  if (myExportFlag)
43  unexportSymbol();
44  }
45 
46  // CMD_SymbolEntry is movable but not copyable
47  CMD_SymbolEntry(CMD_SymbolEntry &&movable) noexcept
48  {
49  operator=(std::move(movable));
50  }
53  {
54  myName = movable.myName;
55  myValue = movable.myValue;
56  myDirtyFlag = movable.myDirtyFlag;
57  myExportFlag = movable.myExportFlag;
58  movable.myExportFlag = false;
59  return *this;
60  }
61 
62  const UT_StringHolder &name() const { return myName; }
63  const UT_StringHolder &value() const { return myValue; }
64  bool isDirty() const { return myDirtyFlag; }
65  bool isExport() const { return myExportFlag; }
66 
68  {
69  myValue = value;
70  if (myExportFlag)
71  exportSymbol();
72  myDirtyFlag = true;
73  }
74 
75  void setDirty(bool f)
76  {
77  myDirtyFlag = f;
78  }
79 
80 private:
81  void exportSymbol();
82  void unexportSymbol();
83 
84  UT_StringHolder myName;
85  UT_StringHolder myValue;
86  bool myDirtyFlag;
87  bool myExportFlag;
88 };
89 
91 {
92 public:
93  virtual ~CMD_SymbolList();
94 
95  bool hasValue(const char *name) const;
96 
97  bool getValue(const char *name, UT_String &value);
98  bool getValue(const char *name, fpreal32 &value);
99  bool getValue(const char *name, fpreal64 &value);
100  bool getValue(const char *name, int64 &value);
101  bool getValue(const char *name, int32 &value);
102 
103  bool setValue(const char *name, const char *value,
104  bool export_var);
105 
106  // Sets the value only if it's different. Returns true if set.
107  bool setValueIfDifferent(
108  const char *name, const char *value,
109  bool export_var);
110 
111  virtual bool destroySymbol(const char *name);
112 
113  exint getSymbolNames(UT_StringArray &nameList);
114 
115  bool setDirty(const char *name, bool dirty);
116 
117 protected:
118  virtual bool isValidSymbolName(const char *name) const;
119 
120  UT_Lock & getLock() const
121  { return myLock; }
122 
124 
125  const TableMap &table() const { return myTable; }
126  TableMap &table() { return myTable; }
127 
128 private:
129  const char *getRawValue(const UT_StringRef &name) const;
130  CMD_SymbolEntry *getSymbolPtr(const UT_StringRef &name);
131 
132 private:
133  TableMap myTable;
134  mutable UT_Lock myLock;
135 };
136 
137 #endif
138 
int int32
Definition: SYS_Types.h:39
UT_Lock & getLock() const
~CMD_SymbolEntry()
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void setValue(const UT_StringHolder &value)
bool isExport() const
int64 exint
Definition: SYS_Types.h:125
TableMap & table()
void setDirty(bool f)
__hostdev__ void setValue(uint32_t offset, bool v)
Definition: NanoVDB.h:5750
UT_StringMap< CMD_SymbolEntry > TableMap
float fpreal32
Definition: SYS_Types.h:200
const UT_StringHolder & name() const
__hostdev__ float getValue(uint32_t i) const
Definition: NanoVDB.h:5578
CMD_SymbolEntry(CMD_SymbolEntry &&movable) noexcept
double fpreal64
Definition: SYS_Types.h:201
CMD_SymbolEntry & operator=(CMD_SymbolEntry &&movable)
GLfloat f
Definition: glcorearb.h:1926
long long int64
Definition: SYS_Types.h:116
bool isDirty() const
GLuint const GLchar * name
Definition: glcorearb.h:786
const TableMap & table() const
#define CMD_API
Definition: CMD_API.h:10
const UT_StringHolder & value() const
Definition: core.h:1131
CMD_SymbolEntry(const char *name, const char *value, bool export_var=false)
UT_NonCopyable & operator=(const UT_NonCopyable &)=delete