HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMG_FileOpt.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: IMG_FileOpt.h ( IMG Library, C++)
7  *
8  * COMMENTS: File options and tags.
9  *
10  * For those familiar with the PRM library, there's sort of a
11  * correspondance between the PRM library and this simple implementation.
12  *
13  * The obvious similarity is between IMG_FileTag and PRM_Name. However,
14  * the similarities continue...
15  *
16  * A PRM_ParmList which contains parameter values is represented here as a
17  * IMG_FileTagList. Each entry in the array corresponds to a name/value
18  * pair. Thus, the tag-list can be appended to, removed, re-ordered etc.
19  * with no effect on how the parameters are interpreted.
20  *
21  * The PRM_TemplateList is similar to the IMG_FileOptionList. Neither
22  * data structure contains any data, but contains the "definitions" for
23  * the available parameters.
24  */
25 
26 #ifndef __IMG_FileOpt__
27 #define __IMG_FileOpt__
28 
29 #include "IMG_API.h"
30 #include <UT/UT_NonCopyable.h>
31 #include <UT/UT_ValArray.h>
32 #include <UT/UT_String.h>
33 
34 class IMG_FileOptionList;
35 
36 // Hints to file options about data types etc.
38  IMG_OPTION_STRING, // Generic string parameter
39  IMG_OPTION_INTEGER, // Integer parameter
40  IMG_OPTION_FLOAT, // Floating point parameter
41 
43 };
44 
46  IMG_FILE_SCOPE_IN = 0x1, // used for input
47  IMG_FILE_SCOPE_OUT = 0x2, // used for output
48  IMG_FILE_SCOPE_NORMAL_RASTER = 0x4, // used where deep rasters aren't supp.
49 
52 };
53 
54 //
55 // Generic token/value pair
57 {
58 public:
59  IMG_FileTag(const char *token=0, const char *value=0)
60  {
61  myToken = token;
62  myValue = value;
63  }
64 
65  int64 getMemoryUsage(bool inclusive) const
66  {
67  int64 mem = inclusive ? sizeof(*this) : 0;
68  mem += myToken.getMemoryUsage(false);
69  mem += myValue.getMemoryUsage(false);
70  return mem;
71  }
72 
73  const char *getToken() const { return myToken; }
74  const char *getValue() const { return myValue; }
75 
76  void setToken(const char *t) { myToken = t; }
77  void setValue(const char *v) { myValue = v; }
78 
79  void harden()
80  {
81  myToken.harden();
82  myValue.harden();
83  }
84 private:
85  UT_String myToken;
86  UT_String myValue;
87 };
88 
90 {
91 public:
94  ~IMG_FileTagList();
95 
97 
98  int64 getMemoryUsage(bool inclusive) const;
99 
100  void setTag(const char *name, const char *value,
101  const IMG_FileOptionList *options=0);
102  void removeTag(const char *name);
103 
104  const char *getTag(const char *name) const;
105  const IMG_FileTag *getTag(int i) const { return myList(i); }
106  int getTagIndex(const char *name) const;
107  int entries() const { return myList.entries(); }
108  void clear();
109 
110 private:
112  unsigned myOwnListFlag:1,
113  mySortedFlag:1;
114 };
115 
117 {
118 public:
120  const char *name=0, const char *label=0,
121  const char *defvalue = 0,
122  IMG_FileTag *menu=0, fpreal min=1, fpreal max=0,
124  : myName(name, label), myMenu(menu)
125  {
126  myHint = hint;
127  myMin = min;
128  myMax = max;
129  myDefault = defvalue;
130  myScope = scope;
131  }
132 
133  const char *getToken() const { return myName.getToken(); }
134  const char *getLabel() const { return myName.getValue(); }
135 
136  const char *getDefault() const { return myDefault; }
137  void setDefault(const char *str)
138  {
139  myDefault.harden(str);
140  }
141 
142  IMG_FileOptionHint getHint() const { return myHint; }
143 
144  int hasMenu() const { return myMenu.entries(); }
145  const IMG_FileTagList &getMenu() const { return myMenu; }
146 
147  // For the option to have a range defined, we require the minimum value to
148  // be less than the maximum value.
149  int hasRange() const { return myMin<myMax; }
150  fpreal getMin() const { return myMin; }
151  fpreal getMax() const { return myMax; }
152 
153  IMG_FileOptionScope getScope() const { return myScope; }
154 
155 private:
156  IMG_FileTag myName;
157  IMG_FileTagList myMenu;
158  UT_String myDefault;
159  fpreal myMin, myMax;
160  IMG_FileOptionHint myHint;
161  IMG_FileOptionScope myScope;
162 };
163 
165 {
166 public:
168 
169  const IMG_FileOption *findOption(const char *token) const;
170  const IMG_FileOption *getOption(int i) const { return myList(i); }
171  int entries() const { return myList.entries(); }
172 
173 private:
175 };
176 
177 #endif
const IMG_FileOption * getOption(int i) const
Definition: IMG_FileOpt.h:170
int entries() const
Definition: IMG_FileOpt.h:107
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
int hasRange() const
Definition: IMG_FileOpt.h:149
const char * getToken() const
Definition: IMG_FileOpt.h:73
const GLdouble * v
Definition: glcorearb.h:837
const char * getToken() const
Definition: IMG_FileOpt.h:133
GLsizei const GLfloat * value
Definition: glcorearb.h:824
fpreal getMax() const
Definition: IMG_FileOpt.h:151
IMG_FileOptionHint
Definition: IMG_FileOpt.h:37
IMG_FileOptionScope
Definition: IMG_FileOpt.h:45
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
const IMG_FileTag * getTag(int i) const
Definition: IMG_FileOpt.h:105
void setToken(const char *t)
Definition: IMG_FileOpt.h:76
IMG_FileOption(IMG_FileOptionHint hint=IMG_OPTION_TERMINATOR, const char *name=0, const char *label=0, const char *defvalue=0, IMG_FileTag *menu=0, fpreal min=1, fpreal max=0, IMG_FileOptionScope scope=IMG_FILE_SCOPE_OUT)
Definition: IMG_FileOpt.h:119
int64 getMemoryUsage(bool inclusive) const
Definition: IMG_FileOpt.h:65
IMG_FileOptionHint getHint() const
Definition: IMG_FileOpt.h:142
const char * getValue() const
Definition: IMG_FileOpt.h:74
#define IMG_API
Definition: IMG_API.h:10
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
const char * getDefault() const
Definition: IMG_FileOpt.h:136
void harden()
Definition: IMG_FileOpt.h:79
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble t
Definition: glad.h:2397
const IMG_FileTagList & getMenu() const
Definition: IMG_FileOpt.h:145
IMG_FileOptionScope getScope() const
Definition: IMG_FileOpt.h:153
IMG_FileTag(const char *token=0, const char *value=0)
Definition: IMG_FileOpt.h:59
fpreal64 fpreal
Definition: SYS_Types.h:277
const char * getLabel() const
Definition: IMG_FileOpt.h:134
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void setValue(const char *v)
Definition: IMG_FileOpt.h:77
Definition: core.h:1131
int entries() const
Definition: IMG_FileOpt.h:171
void setDefault(const char *str)
Definition: IMG_FileOpt.h:137
int hasMenu() const
Definition: IMG_FileOpt.h:144
fpreal getMin() const
Definition: IMG_FileOpt.h:150