HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PRM_Name.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_Name.h (Parameter Library)
7  *
8  * COMMENTS:
9  * This class is used to store names of things which may have
10  * a nice "label" name, and a "token" (more parsable) name.
11  */
12 
13 #ifndef __PRM_Label__
14 #define __PRM_Label__
15 
16 #include "PRM_API.h"
17 #include <UT/UT_IntArray.h>
18 #include <UT/UT_String.h>
19 #include <SYS/SYS_Types.h>
20 
21 class UT_WorkBuffer;
22 
24 {
25 public:
26 
27  /// NOTE: Need an explicit default constructor to work around internal
28  /// compiler error in Visual Studio 2015 Update 3.
29  PRM_Name();
30 
31  /// If thelabel is set to 0, then the thetoken is used as
32  /// the label. Currently the flags parameter is only used for
33  /// the parm expression flag. Set theflags to 1 to make the parm
34  /// default to expression mode.
35  PRM_Name(const char *thetoken,
36  const char *thelabel = 0,
37  int theflags = 0);
38  virtual ~PRM_Name();
39 
40  const char *getToken() const { return myToken; }
41  const char *getLabel() const
42  {
43  return ((const char *)myLabel) ? myLabel : myToken;
44  }
45  int getExpressionFlag() const { return myFlags; }
46  unsigned getHash() const { return myTokenHash; }
47 
48  void setToken(const char *s);
49  void setLabel(const char *s);
50  void harden();
51  void setTokenAndLabel(const char *token, const char *label)
52  {
53  setToken(token);
54  setLabel(label);
55  }
56 
57  void instance(const int *instance, int num);
58  void instance(const UT_IntArray &instance_num);
59 
60  static void instanceToken(UT_String &token, const int *instance, int num);
61  static void instanceToken(UT_String &token,
62  const UT_IntArray &instance_num);
63  static void instanceToken(UT_WorkBuffer &result, const UT_String &token,
64  const int *instance, int num);
65  static void instanceToken(UT_WorkBuffer &result, const UT_String &token,
66  const UT_IntArray &instance_num);
67 
68  bool isValidChoice() const
69  {
70  // First, test that we don't have a null ptr for the token.
71  if (!(const char *)myToken)
72  return false;
73  return myToken.isstring() || myLabel.isstring();
74  }
75 
76  int64 getMemoryUsage(bool inclusive) const
77  {
78  exint mem = inclusive ? sizeof(*this) : 0;
79  mem += myToken.getMemoryUsage(false);
80  mem += myLabel.getMemoryUsage(false);
81  return mem;
82  }
83 
84  static const char *const mySeparator;
85 
86  static const unsigned theSentinelHash;
87 
88 private:
89  void calculateTokenHash();
90 
91  UT_String myToken;
92  UT_String myLabel;
93  unsigned myTokenHash;
94  int myFlags;
95 };
96 #endif
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
int64 getMemoryUsage(bool inclusive) const
Definition: PRM_Name.h:76
unsigned getHash() const
Definition: PRM_Name.h:46
const char * getLabel() const
Definition: PRM_Name.h:41
static const char *const mySeparator
Definition: PRM_Name.h:84
long long int64
Definition: SYS_Types.h:100
int64 exint
Definition: SYS_Types.h:109
void setTokenAndLabel(const char *token, const char *label)
Definition: PRM_Name.h:51
int getExpressionFlag() const
Definition: PRM_Name.h:45
png_infop png_uint_32 int num
Definition: png.h:2158
bool isValidChoice() const
Definition: PRM_Name.h:68
static const unsigned theSentinelHash
Definition: PRM_Name.h:86
#define PRM_API
Definition: PRM_API.h:10
const char * getToken() const
Definition: PRM_Name.h:40