-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode.h
67 lines (59 loc) · 2.3 KB
/
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include "core.h"
#include <vector>
#include <map>
#include <boost/property_tree/ptree.hpp>
class AreaLight;
class Material;
class Geom;
class Scene;
/**
* Wrapper class around a boost::property_tree::ptree to help
* facilitate data access.
*/
class Node {
/** Translator to convert a string to its vector representation. */
struct NodeVecTranslator {
typedef std::string internal_type;
typedef Vec external_type;
NodeVecTranslator();
boost::optional<external_type> get_value(const internal_type& data) const;
};
/** Translator to lookup the object referenced by a string. */
template <typename T, bool allowNull = true>
struct NodeLookupTranslator {
typedef std::string internal_type;
typedef T external_type;
const std::map<internal_type, external_type>& lookup;
NodeLookupTranslator(const std::map<internal_type, external_type>& l);
boost::optional<external_type> get_value(const internal_type& data) const;
};
/** Property tree wrapped by this node. */
const boost::property_tree::ptree& attributes;
/** Scene associated with this node. */
const Scene& container;
public:
/**
* Creates a node from the given property tree and scene. They will be stored
* by reference, and must be kept alive as long as this node is in use.
*/
Node(const boost::property_tree::ptree& attr, const Scene& cont);
/** Gets the string property at the given key. */
std::string getString(std::string key) const;
/** Gets the integer property at the given key. */
int getInt(std::string key) const;
/** Gets the boolean property at the given key. */
bool getBool(std::string key) const;
/** Gets the float property at the given key. */
float getFloat(std::string key) const;
/** Gets the 3D vector property at the given key. */
Vec getVec(std::string key) const;
/** Gets the light pointer referenced by the given key. */
const AreaLight* getLight(std::string key) const;
/** Gets the material pointer referenced by the given key. */
const Material* getMaterial(std::string key) const;
/** Gets the geometry pointer referenced by the given key. */
const Geom* getGeometry(std::string key) const;
/** Gets the geometry pointers referenced in the list with the given key. */
std::vector<const Geom*> getGeometryList(std::string key) const;
};