VR-Forces 4.1 Class Documentation
feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2012 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
8 
9 #pragma once
10 
12 
13 #include <boost/shared_ptr.hpp>
14 #include <boost/function.hpp>
15 #include <boost/variant.hpp>
16 
18 
19 namespace MAKVRinTerra
20 {
28  class DT_DLL_features DtFeature : private boost::noncopyable
29  {
30  public:
31  static const char* TypeName;
32 
33  typedef boost::shared_ptr<DtFeature> Ptr;
34  typedef boost::shared_ptr<const DtFeature> CPtr;
35 
37  typedef boost::variant<
38  std::string,
39  int,
40  double
42 
47  {
49  {
50  public:
51  String();
52  String(const std::string&);
53  String(const char*);
54 
55  const char* c_str() const;
56 
57  bool operator==(const String&) const;
58  bool operator!=(const String&) const;
59  bool operator<(const String&) const;
60 
61  private:
62  std::string myString;
63  };
64 
65  Key(const std::string& name, unsigned index = 0);
66  Key(const String& name, unsigned index = 0);
67  Key(const char* name, unsigned index = 0);
68  Key(const Key& key, unsigned index = 0);
69 
70  bool operator== (const Key&) const;
71  bool operator!= (const Key&) const;
72  bool operator< (const Key&) const;
73 
75  unsigned index;
76  };
77 
79  typedef boost::function<void (const Key&, const Attribute&)> ForEachFunction;
80 
83  static bool Equal(const Attribute&, const Attribute&);
84  static bool NotEqual(const Attribute&, const Attribute&);
85  static bool Less(const Attribute&, const Attribute&);
86  static bool LessOrEqual(const Attribute&, const Attribute&);
87  static bool Greater(const Attribute&, const Attribute&);
88  static bool GreaterOrEqual(const Attribute&, const Attribute&);
90 
92  static std::string TypeOfAttribute(const Attribute&);
93 
95  static CPtr GetPtr(const DtFeature&);
96 
98  static Ptr CreateEmptyFeature();
99 
101  static Ptr CreateGeometryFeature(DtFeatureGeometry);
102 
105  static Ptr CreateCopy(const DtFeature& feature);
106 
108  virtual ~DtFeature();
109 
116  virtual CPtr getPtr() const;
117 
123  virtual DtFeatureGeometry geometry() const = 0;
124 
126  virtual void forEachAttribute(ForEachFunction f) const = 0;
127 
129  virtual unsigned numberOfAttributes(const Key::String &) const = 0;
130 
132  virtual bool hasAttribute(const Key & k) const;
133 
135  virtual boost::optional<Attribute> attribute(const Key &) const = 0;
136 
137  template <typename T>
138  boost::optional<T> attributeAs(const Key& k) const
139  {
140  if (boost::optional<Attribute> attr = attribute(k))
141  return boost::apply_visitor(AttributeConverter<T>(), *attr);
142 
143  return boost::optional<T>();
144  }
145 
146  template <typename Feature>
147  class Wrapper;
148 
149  private:
150  template <typename T>
151  struct AttributeConverter : public boost::static_visitor< boost::optional<T> >
152  {
153  template <typename From>
154  boost::optional<T> operator()(const From& from) const
155  {
156  try
157  {
158  return boost::lexical_cast<T>(from);
159  }
160  catch (boost::bad_lexical_cast&)
161  {
162  return boost::optional<T>();
163  }
164  }
165  };
166  };
167 
168  template <typename Feature>
169  class DtFeatureWrapper : public Feature
170  {
171  public:
172  typedef typename Feature::ForEachFunction ForEachFunction;
173  typedef typename Feature::Attribute Attribute;
174  typedef typename Feature::Key Key;
175 
176  typename Feature::CPtr getPtr() const { return typename Feature::Ptr(clone()); }
177 
178  DtFeatureGeometry geometry() const { return myWrappedFeature->geometry(); }
179 
181  {
182  myWrappedFeature->forEachAttribute(func);
183  }
184 
185  unsigned numberOfAttributes(const typename Key::String& str) const
186  {
187  return myWrappedFeature->numberOfAttributes(str);
188  }
189 
190  boost::optional<Attribute> attribute(const Key& key) const
191  {
192  return myWrappedFeature->attribute(key);
193  }
194 
195  protected:
196  explicit DtFeatureWrapper(const Feature& f)
197  : myWrappedFeature(Feature::GetPtr(f)) { }
198 
199  explicit DtFeatureWrapper(typename Feature::CPtr f)
200  : myWrappedFeature(f) { }
201 
202  virtual DtFeatureWrapper* clone() const = 0;
203 
204  typename Feature::CPtr myWrappedFeature;
205  };
206 
207  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature::Attribute&);
208  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature&);
209  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature::Key&);
210  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature::Key::String&);
211 }

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)