00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00037
00038
00039 #ifndef OPENIMAGEIO_PARAMLIST_H
00040 #define OPENIMAGEIO_PARAMLIST_H
00041
00042 #include <vector>
00043
00044 #include "export.h"
00045 #include "typedesc.h"
00046 #include "ustring.h"
00047
00048
00049 #ifdef OPENIMAGEIO_NAMESPACE
00050 namespace OPENIMAGEIO_NAMESPACE {
00051 #endif
00052
00053
00054
00055
00056
00064 class DLLPUBLIC ParamValue {
00065 public:
00068 enum Interp {
00069 INTERP_CONSTANT = 0,
00070 INTERP_PERPIECE = 1,
00071 INTERP_LINEAR = 2,
00072 INTERP_VERTEX = 3
00073 };
00074
00075 ParamValue () : m_type(TypeDesc::UNKNOWN), m_nvalues(0),
00076 m_interp(INTERP_CONSTANT), m_copy(false), m_nonlocal(false)
00077 {
00078 m_data.ptr = NULL;
00079 }
00080 ParamValue (const ustring &_name, TypeDesc _type,
00081 int _nvalues, const void *_value, bool _copy=true) {
00082 init_noclear (_name, _type, _nvalues, _value, _copy);
00083 }
00084 ParamValue (const std::string &_name, TypeDesc _type,
00085 int _nvalues, const void *_value, bool _copy=true) {
00086 init_noclear (ustring(_name.c_str()), _type, _nvalues, _value, _copy);
00087 }
00088 ParamValue (const char *_name, TypeDesc _type,
00089 int _nvalues, const void *_value, bool _copy=true) {
00090 init_noclear (ustring(_name), _type, _nvalues, _value, _copy);
00091 }
00092 ParamValue (const ParamValue &p, bool _copy=true) {
00093 init_noclear (p.name(), p.type(), p.nvalues(), p.data(), _copy);
00094 }
00095 ~ParamValue () { clear_value(); }
00096 void init (ustring _name, TypeDesc _type,
00097 int _nvalues, const void *_value, bool _copy=true) {
00098 clear_value ();
00099 init_noclear (_name, _type, _nvalues, _value, _copy);
00100 }
00101 void init (std::string _name, TypeDesc _type,
00102 int _nvalues, const void *_value, bool _copy=true) {
00103 init (ustring(_name), _type, _nvalues, _value, _copy);
00104 }
00105 const ParamValue& operator= (const ParamValue &p) {
00106 init (p.name(), p.type(), p.nvalues(), p.data(), p.m_copy);
00107 return *this;
00108 }
00109
00110 const ustring &name () const { return m_name; }
00111 TypeDesc type () const { return m_type; }
00112 int nvalues () const { return m_nvalues; }
00113 const void *data () const { return m_nonlocal ? m_data.ptr : &m_data; }
00114 int datasize () const { return m_nvalues * m_type.size(); }
00115
00116 friend void swap (ParamValue &a, ParamValue &b) {
00117 std::swap (a.m_name, b.m_name);
00118 std::swap (a.m_type, b.m_type);
00119 std::swap (a.m_nvalues, b.m_nvalues);
00120 std::swap (a.m_data.ptr, b.m_data.ptr);
00121 std::swap (a.m_copy, b.m_copy);
00122 std::swap (a.m_nonlocal, b.m_nonlocal);
00123 }
00124
00125 private:
00126 ustring m_name;
00127 TypeDesc m_type;
00128 int m_nvalues;
00129 union {
00130 ptrdiff_t localval;
00131 const void *ptr;
00132 } m_data;
00133 unsigned char m_interp;
00134 bool m_copy, m_nonlocal;
00135
00136 void init_noclear (ustring _name, TypeDesc _type,
00137 int _nvalues, const void *_value, bool _copy=true);
00138 void clear_value();
00139 };
00140
00141
00142
00145 class DLLPUBLIC ParamValueList {
00146 typedef std::vector<ParamValue> Rep;
00147 public:
00148 ParamValueList () { }
00149
00150 typedef Rep::iterator iterator;
00151 typedef Rep::const_iterator const_iterator;
00152 typedef ParamValue value_type;
00153 typedef value_type & reference;
00154 typedef const value_type & const_reference;
00155 typedef value_type * pointer;
00156 typedef const value_type * const_pointer;
00157
00158 iterator begin () { return m_vals.begin(); }
00159 iterator end () { return m_vals.end(); }
00160 const_iterator begin () const { return m_vals.begin(); }
00161 const_iterator end () const { return m_vals.end(); }
00162
00163 reference front () { return m_vals.front(); }
00164 reference back () { return m_vals.back(); }
00165 const_reference front () const { return m_vals.front(); }
00166 const_reference back () const { return m_vals.back(); }
00167
00168 reference operator[] (int i) { return m_vals[i]; }
00169 const_reference operator[] (int i) const { return m_vals[i]; }
00170 reference operator[] (size_t i) { return m_vals[i]; }
00171 const_reference operator[] (size_t i) const { return m_vals[i]; }
00172
00173 void resize (size_t newsize) { m_vals.resize (newsize); }
00174 size_t size () const { return m_vals.size(); }
00175
00178 void clear () { m_vals.clear(); }
00179
00182 void free () { Rep tmp; std::swap (m_vals, tmp); }
00183
00184 private:
00185 Rep m_vals;
00186 };
00187
00188
00189
00190
00191
00192
00193
00194 #ifdef OPENIMAGEIO_NAMESPACE
00195 };
00196 using namespace OPENIMAGEIO_NAMESPACE;
00197 #endif
00198
00199 #endif