Nori  24
proplist.h
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob, Romain Prévost
5 
6  Nori is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Nori is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #if !defined(__NORI_PROPLIST_H)
20 #define __NORI_PROPLIST_H
21 
22 #include <nori/color.h>
23 #include <nori/transform.h>
24 #include <map>
25 
26 NORI_NAMESPACE_BEGIN
27 
32 class PropertyList {
33 public:
34  PropertyList() { }
35 
36  bool has(const std::string & name) const {
37  return (m_properties.find(name) != m_properties.end());
38  }
39 
41  void setBoolean(const std::string &name, const bool &value);
42 
44  bool getBoolean(const std::string &name) const;
45 
47  bool getBoolean(const std::string &name, const bool &defaultValue) const;
48 
50  void setInteger(const std::string &name, const int &value);
51 
53  int getInteger(const std::string &name) const;
54 
56  int getInteger(const std::string &name, const int &defaultValue) const;
57 
59  void setFloat(const std::string &name, const float &value);
60 
62  float getFloat(const std::string &name) const;
63 
65  float getFloat(const std::string &name, const float &defaultValue) const;
66 
68  void setString(const std::string &name, const std::string &value);
69 
71  std::string getString(const std::string &name) const;
72 
74  std::string getString(const std::string &name, const std::string &defaultValue) const;
75 
77  void setColor(const std::string &name, const Color3f &value);
78 
80  Color3f getColor(const std::string &name) const;
81 
83  Color3f getColor(const std::string &name, const Color3f &defaultValue) const;
84 
86  void setPoint3(const std::string &name, const Point3f &value);
87 
89  Point3f getPoint3(const std::string &name) const;
90 
92  Point3f getPoint3(const std::string &name, const Point3f &defaultValue) const;
93 
95  void setVector3(const std::string &name, const Vector3f &value);
96 
98  Vector3f getVector3(const std::string &name) const;
99 
101  Vector3f getVector3(const std::string &name, const Vector3f &defaultValue) const;
102 
104  void setPoint2(const std::string &name, const Point2f &value);
105 
107  Point2f getPoint2(const std::string &name) const;
108 
110  Point2f getPoint2(const std::string &name, const Point2f &defaultValue) const;
111 
113  void setVector2(const std::string &name, const Vector2f &value);
114 
116  Vector2f getVector2(const std::string &name) const;
117 
119  Vector2f getVector2(const std::string &name, const Vector2f &defaultValue) const;
120 
122  void setTransform(const std::string &name, const Transform &value);
123 
125  Transform getTransform(const std::string &name) const;
126 
128  Transform getTransform(const std::string &name, const Transform &defaultValue) const;
129 private:
130  /* Custom variant data type (stores one of boolean/integer/float/...) */
131  struct Property {
132  enum {
133  Boolean_type, Integer_type, Float_type,
134  String_type, Color_type, Point3_type,
135  Vector3_type, Point2_type,
136  Vector2_type, Transform_type
137  } type;
138 
139  /* Visual studio lacks support for unrestricted unions (as of ver. 2013) */
140  struct Value
141  {
142  Value() : Boolean_value(false) { }
143  ~Value() { }
144 
145  bool Boolean_value;
146  int Integer_value;
147  float Float_value;
148  std::string String_value;
149  Color3f Color_value;
150  Point3f Point3_value;
151  Vector3f Vector3_value;
152  Point2f Point2_value;
153  Vector2f Vector2_value;
154  Transform Transform_value;
155  } value;
156 
157  Property() : type(Boolean_type) { }
158  };
159 
160  std::map<std::string, Property> m_properties;
161 };
162 
163 NORI_NAMESPACE_END
164 
165 #endif /* __NORI_PROPLIST_H */
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition: proplist.h:32
Vector3f getVector3(const std::string &name) const
Get a vector property, and throw an exception if it does not exist.
void setFloat(const std::string &name, const float &value)
Set a float property.
void setColor(const std::string &name, const Color3f &value)
Set a color property.
Transform getTransform(const std::string &name) const
Get a transform property, and throw an exception if it does not exist.
Point2f getPoint2(const std::string &name) const
Get a point property, and throw an exception if it does not exist.
Transform getTransform(const std::string &name, const Transform &defaultValue) const
Get a transform property, and use a default value if it does not exist.
int getInteger(const std::string &name, const int &defaultValue) const
Get am integer property, and use a default value if it does not exist.
void setPoint3(const std::string &name, const Point3f &value)
Set a point property.
void setBoolean(const std::string &name, const bool &value)
Set a boolean property.
Vector3f getVector3(const std::string &name, const Vector3f &defaultValue) const
Get a vector property, and use a default value if it does not exist.
float getFloat(const std::string &name) const
Get a float property, and throw an exception if it does not exist.
bool getBoolean(const std::string &name, const bool &defaultValue) const
Get a boolean property, and use a default value if it does not exist.
void setVector3(const std::string &name, const Vector3f &value)
Set a vector property.
std::string getString(const std::string &name) const
Get a string property, and throw an exception if it does not exist.
Vector2f getVector2(const std::string &name, const Vector2f &defaultValue) const
Get a vector property, and use a default value if it does not exist.
Point3f getPoint3(const std::string &name) const
Get a point property, and throw an exception if it does not exist.
Vector2f getVector2(const std::string &name) const
Get a vector property, and throw an exception if it does not exist.
bool getBoolean(const std::string &name) const
Get a boolean property, and throw an exception if it does not exist.
Color3f getColor(const std::string &name) const
Get a color property, and throw an exception if it does not exist.
void setVector2(const std::string &name, const Vector2f &value)
Set a vector property.
void setString(const std::string &name, const std::string &value)
Set a string property.
Color3f getColor(const std::string &name, const Color3f &defaultValue) const
Get a color property, and use a default value if it does not exist.
Point2f getPoint2(const std::string &name, const Point2f &defaultValue) const
Get a point property, and use a default value if it does not exist.
void setPoint2(const std::string &name, const Point2f &value)
Set a point property.
Point3f getPoint3(const std::string &name, const Point3f &defaultValue) const
Get a point property, and use a default value if it does not exist.
int getInteger(const std::string &name) const
Get an integer property, and throw an exception if it does not exist.
float getFloat(const std::string &name, const float &defaultValue) const
Get a float property, and use a default value if it does not exist.
std::string getString(const std::string &name, const std::string &defaultValue) const
Get a string property, and use a default value if it does not exist.
void setTransform(const std::string &name, const Transform &value)
Set a transform property.
void setInteger(const std::string &name, const int &value)
Set an integer property.
Represents a linear RGB color value.
Definition: color.h:29
Homogeneous coordinate transformation.
Definition: transform.h:35