HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_ValArray.h>
31 #include <UT/UT_String.h>
32 
33 class IMG_FileOptionList;
34 
35 // Hints to file options about data types etc.
37  IMG_OPTION_STRING, // Generic string parameter
38  IMG_OPTION_INTEGER, // Integer parameter
39  IMG_OPTION_FLOAT, // Floating point parameter
40 
42 };
43 
45  IMG_FILE_SCOPE_IN = 0x1, // used for input
46  IMG_FILE_SCOPE_OUT = 0x2, // used for output
47  IMG_FILE_SCOPE_NORMAL_RASTER = 0x4 // used where deep rasters aren't supp.
48 };
49 
50 #define IMG_FILE_SCOPE_INOUT \
51  (IMG_FileOptionScope)((IMG_FILE_SCOPE_IN|IMG_FILE_SCOPE_OUT))
52 
53 //
54 // Generic token/value pair
56 public:
57  IMG_FileTag(const char *token=0, const char *value=0)
58  {
59  myToken = token;
60  myValue = value;
61  }
63 
64  int64 getMemoryUsage(bool inclusive) const
65  {
66  int64 mem = inclusive ? sizeof(*this) : 0;
67  mem += myToken.getMemoryUsage(false);
68  mem += myValue.getMemoryUsage(false);
69  return mem;
70  }
71 
72  const char *getToken() const { return myToken; }
73  const char *getValue() const { return myValue; }
74 
75  void setToken(const char *t) { myToken = t; }
76  void setValue(const char *v) { myValue = v; }
77 
78  void harden()
79  {
80  myToken.harden();
81  myValue.harden();
82  }
83 private:
84  UT_String myToken;
85  UT_String myValue;
86 };
87 
89 public:
92  ~IMG_FileTagList();
93 
94  int64 getMemoryUsage(bool inclusive) const;
95 
96  void setTag(const char *name, const char *value,
97  const IMG_FileOptionList *options=0);
98  void removeTag(const char *name);
99 
100  const char *getTag(const char *name) const;
101  const IMG_FileTag *getTag(int i) const { return myList(i); }
102  int getTagIndex(const char *name) const;
103  int entries() const { return myList.entries(); }
104  void clear();
105 
106 private:
108  unsigned myOwnListFlag:1,
109  mySortedFlag:1;
110 };
111 
113 public:
115  const char *name=0, const char *label=0,
116  const char *defvalue = 0,
117  IMG_FileTag *menu=0, fpreal min=1, fpreal max=0,
119  : myName(name, label), myMenu(menu)
120  {
121  myHint = hint;
122  myMin = min;
123  myMax = max;
124  myDefault = defvalue;
125  myScope = scope;
126  }
127  ~IMG_FileOption();
128 
129  const char *getToken() const { return myName.getToken(); }
130  const char *getLabel() const { return myName.getValue(); }
131 
132  const char *getDefault() const { return myDefault; }
133  void setDefault(const char *str)
134  {
135  myDefault.harden(str);
136  }
137 
138  IMG_FileOptionHint getHint() const { return myHint; }
139 
140  int hasMenu() const { return myMenu.entries(); }
141  const IMG_FileTagList &getMenu() const { return myMenu; }
142 
143  // For the option to have a range defined, we require the minimum value to
144  // be less than the maximum value.
145  int hasRange() const { return myMin<myMax; }
146  fpreal getMin() const { return myMin; }
147  fpreal getMax() const { return myMax; }
148 
149  IMG_FileOptionScope getScope() const { return myScope; }
150 
151 private:
152  IMG_FileTag myName;
153  IMG_FileTagList myMenu;
154  UT_String myDefault;
155  fpreal myMin, myMax;
156  IMG_FileOptionHint myHint;
157  IMG_FileOptionScope myScope;
158 };
159 
161 public:
164 
165  const IMG_FileOption *findOption(const char *token) const;
166  const IMG_FileOption *getOption(int i) const { return myList(i); }
167  int entries() const { return myList.entries(); }
168 
169 private:
171 };
172 
173 #endif
const IMG_FileOption * getOption(int i) const
Definition: IMG_FileOpt.h:166
int entries() const
Definition: IMG_FileOpt.h:103
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
int hasRange() const
Definition: IMG_FileOpt.h:145
const char * getToken() const
Definition: IMG_FileOpt.h:72
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
const GLdouble * v
Definition: glcorearb.h:836
const char * getToken() const
Definition: IMG_FileOpt.h:129
fpreal getMax() const
Definition: IMG_FileOpt.h:147
IMG_FileOptionHint
Definition: IMG_FileOpt.h:36
IMG_FileOptionScope
Definition: IMG_FileOpt.h:44
const IMG_FileTag * getTag(int i) const
Definition: IMG_FileOpt.h:101
void setToken(const char *t)
Definition: IMG_FileOpt.h:75
png_uint_32 i
Definition: png.h:2877
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:114
int64 getMemoryUsage(bool inclusive) const
Definition: IMG_FileOpt.h:64
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
IMG_FileOptionHint getHint() const
Definition: IMG_FileOpt.h:138
const char * getValue() const
Definition: IMG_FileOpt.h:73
long long int64
Definition: SYS_Types.h:100
#define IMG_API
Definition: IMG_API.h:10
const char * getDefault() const
Definition: IMG_FileOpt.h:132
void harden()
Definition: IMG_FileOpt.h:78
GLuint const GLchar * name
Definition: glcorearb.h:785
const IMG_FileTagList & getMenu() const
Definition: IMG_FileOpt.h:141
IMG_FileOptionScope getScope() const
Definition: IMG_FileOpt.h:149
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:263
IMG_FileTag(const char *token=0, const char *value=0)
Definition: IMG_FileOpt.h:57
const char * getLabel() const
Definition: IMG_FileOpt.h:130
void setValue(const char *v)
Definition: IMG_FileOpt.h:76
int entries() const
Definition: IMG_FileOpt.h:167
void setDefault(const char *str)
Definition: IMG_FileOpt.h:133
int hasMenu() const
Definition: IMG_FileOpt.h:140
fpreal getMin() const
Definition: IMG_FileOpt.h:146