Nori  24
proplist.cpp
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 #include <nori/proplist.h>
20 
21 NORI_NAMESPACE_BEGIN
22 
23 #define DEFINE_PROPERTY_ACCESSOR(Type, TypeName, XmlName) \
24  void PropertyList::set##TypeName(const std::string &name, const Type &value) { \
25  if (m_properties.find(name) != m_properties.end()) \
26  cerr << "Property \"" << name << "\" was specified multiple times!" << endl; \
27  auto &prop = m_properties[name]; \
28  prop.value.TypeName##_value = value; \
29  prop.type = Property::TypeName##_type; \
30  } \
31  \
32  Type PropertyList::get##TypeName(const std::string &name) const { \
33  auto it = m_properties.find(name); \
34  if (it == m_properties.end()) \
35  throw NoriException("Property '%s' is missing!", name); \
36  if (it->second.type != Property::TypeName##_type) \
37  throw NoriException("Property '%s' has the wrong type! " \
38  "(expected <" #XmlName ":" #TypeName ">)!", name); \
39  return it->second.value.TypeName##_value; \
40  } \
41  \
42  Type PropertyList::get##TypeName(const std::string &name, const Type &defVal) const { \
43  auto it = m_properties.find(name); \
44  if (it == m_properties.end()) \
45  return defVal; \
46  if (it->second.type != Property::TypeName##_type) \
47  throw NoriException("Property '%s' has the wrong type! " \
48  "(expected <" #XmlName ":" #TypeName ">)!", name); \
49  return it->second.value.TypeName##_value; \
50  }
51 
52 DEFINE_PROPERTY_ACCESSOR(bool, Boolean, boolean)
53 DEFINE_PROPERTY_ACCESSOR(int, Integer, integer)
54 DEFINE_PROPERTY_ACCESSOR(float, Float, float)
55 DEFINE_PROPERTY_ACCESSOR(Color3f, Color, color)
56 DEFINE_PROPERTY_ACCESSOR(Point3f, Point3, point)
57 DEFINE_PROPERTY_ACCESSOR(Vector3f, Vector3, vector)
58 DEFINE_PROPERTY_ACCESSOR(Point2f, Point2, point)
59 DEFINE_PROPERTY_ACCESSOR(Vector2f, Vector2, vector)
60 DEFINE_PROPERTY_ACCESSOR(std::string, String, string)
61 DEFINE_PROPERTY_ACCESSOR(Transform, Transform, transform)
62 
63 NORI_NAMESPACE_END
64 
Represents a linear RGB color value.
Definition: color.h:29
Homogeneous coordinate transformation.
Definition: transform.h:35