1 #ifndef SIMGEAR_EXTENDEDPROPERTYADAPTER_HXX
2 #define SIMGEAR_EXTENDEDPROPERTYADAPTER_HXX 1
6 #include <boost/bind.hpp>
8 #include <simgear/math/SGMath.hxx>
9 #include <simgear/structure/exception.hxx>
18 // This should be in simgear/math/SGVec.hxx and friends
20 template<typename T> struct NumComponents;
22 template<> struct NumComponents<SGVec3d>
24 enum { num_components = 3 };
27 template<> struct NumComponents<SGVec4d>
29 enum { num_components = 4 };
34 template<typename T, typename NodeContainer>
35 class ExtendedPropertyAdapter
38 enum { num_components = props::NumComponents<T>::num_components };
39 ExtendedPropertyAdapter(const NodeContainer& elements)
46 if (_elements.size() < num_components)
48 for (int i = 0; i < num_components; ++i)
49 result[i] = _elements[i]->template getValue<double>();
52 void set(const T& val)
54 if (_elements.size() < num_components)
56 for (int i = 0; i < num_components; ++i)
57 _elements[i]->setValue(val[i]);
60 const NodeContainer& _elements;
63 template<typename InIterator, typename OutIterator>
64 inline void makeChildList(SGPropertyNode* prop, InIterator inBegin,
65 InIterator inEnd, OutIterator outBegin)
67 std::transform(inBegin, inEnd, outBegin,
68 boost::bind(static_cast<SGPropertyNode* (SGPropertyNode::*)(const char*, int, bool)>(&SGPropertyNode::getChild), prop, _1, 0, true));