1 // Some helper functions for accessing the property tree
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef PROPERTY_HELPER_HXX_
20 #define PROPERTY_HELPER_HXX_
22 #include <simgear/props/props.hxx>
29 * Get property node with default value
32 SGPropertyNode* getChildDefault( SGPropertyNode* parent,
36 SGPropertyNode* node = parent->getNode(name);
38 // also set value for existing nodes to enforce type...
39 def_val = getValue<T>(node);
41 node = parent->getChild(name, 0, true);
43 setValue(node, def_val);
48 * Get vector of properties
50 template<typename T, typename T_get /* = T */> // TODO use C++11 or traits
51 std::vector<T> getVectorFromChildren( const SGPropertyNode* parent,
52 const char* child_name )
54 const simgear::PropertyList& props = parent->getChildren(child_name);
55 std::vector<T> values( props.size() );
57 for( size_t i = 0; i < props.size(); ++i )
58 values[i] = getValue<T_get>(props[i]);
64 * @param name Name of color node
65 * @param parent Parent for color channel nodes
66 * @param nodes Vector to push color nodes into
67 * @param def Default color
70 * <red type="float">def[0] or existing value</red>
71 * <green type="float">def[1] or existing value</green>
72 * <blue type="float">def[2] or existing value</blue>
73 * <alpha type="float">def[3] or existing value</alpha>
76 void linkColorNodes( const char* name,
77 SGPropertyNode* parent,
78 std::vector<SGPropertyNode_ptr>& nodes,
79 const osg::Vec4& def = osg::Vec4(0,0,0,1) );
83 #endif /* PROPERTY_HELPER_HXX_ */