00001 #ifndef __PARAMETERS_H__
00002 #define __PARAMETERS_H__
00003
00004 #include <set>
00005 #include <map>
00006 #include <list>
00007 #include <string>
00008 #include <utility>
00009 #include <stdint.h>
00010 #include <math.h>
00011
00012 #include "stm_export.h"
00013
00014 namespace spectral
00015 {
00016
00017 enum
00018 {
00019 PARAM_TYPE_NONE = 0,
00020 PARAM_TYPE_BOOL,
00021 PARAM_TYPE_INT,
00022 PARAM_TYPE_FLOAT,
00023 PARAM_TYPE_ENUM,
00024 PARAM_TYPE_CHROMATICITY
00025 };
00026
00028
00030
00031
00032 class Chromaticity
00033 {
00034 public:
00035 Chromaticity()
00036 : m_x(0)
00037 , m_y(0)
00038 {
00039 }
00040 Chromaticity(float x, float y)
00041 : m_x(x), m_y(y)
00042 {}
00043
00044 Chromaticity(const Chromaticity &other)
00045 {
00046 other.GetXY(m_x, m_y);
00047 }
00048
00049 Chromaticity &operator=(const Chromaticity &other)
00050 {
00051 other.GetXY(m_x, m_y);
00052 return *this;
00053 }
00054 void GetXY(float &x, float &y) const
00055 {
00056 x = m_x;
00057 y = m_y;
00058 }
00059 private:
00060 float m_x, m_y;
00061 };
00062
00064
00066 class FloatParameter
00067 {
00068 public:
00069 FloatParameter()
00070 : m_value(0)
00071 , m_min(0)
00072 , m_max(0)
00073 {
00074 }
00075 FloatParameter(float min, float max, float value)
00076 : m_value(value)
00077 , m_min((min<max)?min:max)
00078 , m_max((min>max)?min:max)
00079 {
00080 }
00081 void GetValue(float &) const;
00082 void GetRange(float &, float &) const;
00083 bool SetValue(float value);
00084
00085 private:
00086 float m_value, m_min, m_max;
00087 };
00088
00089 class IntParameter
00090 {
00091 public:
00092 IntParameter()
00093 : m_value(0)
00094 , m_min(0)
00095 , m_max(0)
00096 {
00097 }
00098 IntParameter(int32_t min, int32_t max, int32_t value)
00099 : m_value(value)
00100 , m_min((min<max)?min:max)
00101 , m_max((min>max)?min:max)
00102 {
00103 }
00104 void GetValue(int32_t &) const;
00105 void GetRange(int32_t &, int32_t &) const;
00106 bool SetValue(int32_t value);
00107
00108 private:
00109 int32_t m_value, m_min, m_max;
00110 };
00111
00112 class EnumParameter
00113 {
00114 public:
00115 EnumParameter();
00116 EnumParameter(const EnumParameter &other);
00117 EnumParameter(const std::list<std::pair<uint32_t, std::string> > &,
00118 uint32_t);
00119
00120 void GetRange(std::list<std::pair<uint32_t, std::string> > &) const;
00121 void GetValue(uint32_t &, std::string &) const;
00122 bool SetValue(uint32_t value);
00123
00124 private:
00125 void SetRange(const std::list<std::pair<uint32_t, std::string> > &);
00126 uint32_t m_value;
00127 std::map<uint32_t, std::string> m_range;
00128 };
00129
00131
00133 class STM_EXPORT Parameters
00134 {
00135 public:
00136 Parameters();
00137 ~Parameters();
00138
00139
00140 void SetDirty(void) { m_dirty = true; }
00141 void SetClean(void) { m_dirty = false; }
00142 bool IsDirty(void) const { return m_dirty; }
00143
00144 uint32_t GetParameterType(std::string name) const;
00145 void GetParameterNames(std::list<std::string> &names) const;
00146
00147
00148 bool AddParameter(std::string name, bool value);
00149 bool SetParameter(std::string name, bool value);
00150 bool GetParameter(std::string name, bool &value) const;
00151
00152
00153 bool AddParameter(std::string name, float min, float max, float value);
00154 bool SetParameter(std::string name, float value);
00155 bool GetParameter(std::string name, float &value) const;
00156 bool GetRange(std::string name, float &min, float &max) const;
00157
00158
00159 bool AddParameter(std::string name, int32_t min, int32_t max,
00160 int32_t value);
00161 bool SetParameter(std::string name, int32_t value);
00162 bool GetParameter(std::string name, int32_t &value) const;
00163 bool GetRange(std::string name, int32_t &min, int32_t &max) const;
00164
00165
00166 bool AddParameter(std::string name,
00167 const std::list<std::pair<uint32_t, std::string> > &,
00168 uint32_t value);
00169 bool SetParameter(std::string name, uint32_t);
00170 bool GetParameter(std::string name, uint32_t &, std::string &) const;
00171 bool GetRange(std::string name,
00172 std::list<std::pair<uint32_t, std::string> > &) const;
00173
00174
00175 bool AddParameter(std::string name, Chromaticity value);
00176 bool SetParameter(std::string name, Chromaticity value);
00177 bool GetParameter(std::string name, Chromaticity &value) const;
00178
00179 private:
00180 std::list<std::string> m_names;
00181 std::map<std::string, uint32_t> m_allParams;
00182 std::map<std::string, bool> m_boolParams;
00183 std::map<std::string, IntParameter> m_intParams;
00184 std::map<std::string, FloatParameter> m_floatParams;
00185 std::map<std::string, EnumParameter> m_enumParams;
00186 std::map<std::string, Chromaticity> m_chromaParams;
00187
00188 bool m_dirty;
00189 };
00190
00191 }
00192
00193 #endif