00001 #ifndef __INSTANTIO_COLOR_H
00002 #define __INSTANTIO_COLOR_H
00003
00004 #ifdef _MSC_VER
00005 # pragma once
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "InstantIODef.h"
00027 #include "TypeName.h"
00028 #ifdef _MSC_VER
00029 # pragma warning (push)
00030 # pragma warning (disable: 4351)
00031 #endif
00032
00033
00034 namespace InstantIO
00035 {
00036
00037
00056 class INSTANTIO_DLLMAPPING Color
00057 {
00058 public:
00059
00064 inline Color(): color_()
00065 { color_[0] = color_[1] = color_[2] = 0.f; }
00066
00074 inline Color(float r, float g, float b): color_()
00075 { color_[0] = r; color_[1] = g; color_[2] = b; }
00076
00086 inline Color(const float *color): color_()
00087 { color_[0] = color[0]; color_[1] = color[1]; color_[2] = color[2]; }
00088
00094 inline Color(const Color &color): color_()
00095 { color_[0] = color.color_[0]; color_[1] = color.color_[1]; color_[2] = color.color_[2]; }
00096
00103 inline const Color &operator=(const Color &color)
00104 {
00105 color_[0] = color.color_[0]; color_[1] = color.color_[1]; color_[2] = color.color_[2];
00106 return color;
00107 }
00108
00118 inline const float *operator =(const float *color)
00119 {
00120 color_[0] = color[0]; color_[1] = color[1]; color_[2] = color[2];
00121 return color;
00122 }
00123
00128 inline void setR(float r) { color_[0] = r; }
00129
00134 inline float getR() const { return color_[0]; }
00135
00140 inline void setG(float g) { color_[1] = g; }
00141
00146 inline float getG() const { return color_[1]; }
00147
00152 inline void setB(float b) { color_[2] = b; }
00153
00158 inline float getB() const { return color_[2]; }
00159
00166 inline void set(float r, float g, float b)
00167 { color_[0] = r; color_[1] = g; color_[2] = b; }
00168
00177 inline void set(const float *color)
00178 { color_[0] = color[0]; color_[1] = color[1]; color_[2] = color[2]; }
00179
00184 void set(const Color &color)
00185 {
00186 color_[0] = color.color_[0];
00187 color_[1] = color.color_[1];
00188 color_[2] = color.color_[2];
00189 }
00190
00197 inline void get(float &r, float &g, float &b) const
00198 { r = color_[0]; g = color_[1]; b = color_[2]; }
00199
00209 inline void get(float *color) const
00210 { color[0] = color_[0]; color[1] = color_[1]; color[2] = color_[2]; }
00211
00217 inline void get(Color &color) const
00218 { color.color_[0] = color_[0]; color.color_[1] = color_[1]; color.color_[2] = color_[2]; }
00219
00227 inline const float *get() const { return color_; }
00228
00236 inline float *get() { return color_; }
00237
00243 inline float operator[](int i) const { return color_[i]; }
00244
00250 inline float &operator[](int i) { return color_[i]; }
00251
00256 inline operator float *() { return &color_[0]; }
00257
00262 inline operator const float *() const { return &color_[0]; }
00263
00271 friend inline bool operator==(const Color &a, const Color &b)
00272 {
00273 return (a.color_[0] == b.color_[0]) && (a.color_[1] == b.color_[1]) && (a.color_[2] == b.color_[2]);
00274 }
00275
00283 friend inline bool operator!=(const Color &a, const Color &b)
00284 {
00285 return (a.color_[0] != b.color_[0]) || (a.color_[1] != b.color_[1]) || (a.color_[2] != b.color_[2]);
00286 }
00287
00288 private:
00289
00291 float color_[3];
00292 };
00293
00294
00301 template <>
00302 class INSTANTIO_DLLMAPPING TypeName<Color>
00303 {
00304 public:
00305
00310 static const char *getName();
00311
00312 private:
00313
00315 TypeName();
00316
00318 TypeName(const TypeName &);
00319
00321 const TypeName &operator=(const TypeName &);
00322 };
00323
00324
00325 }
00326
00327
00328 #ifdef _MSC_VER
00329 # pragma warning (pop)
00330 #endif
00331
00332 #endif // __INSTANTIO_COLOR_H