VR-Forces 4.2 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 CreateGeometryFeature(
106  DtFeatureGeometry, unsigned char red, unsigned char green, unsigned char blue);
107 
110  static Ptr CreateCopy(const DtFeature& feature);
111 
113  virtual ~DtFeature();
114 
121  virtual CPtr getPtr() const;
122 
128  virtual DtFeatureGeometry geometry() const = 0;
129 
131  virtual void forEachAttribute(ForEachFunction f) const = 0;
132 
134  virtual unsigned numberOfAttributes(const Key::String &) const = 0;
135 
137  virtual bool hasAttribute(const Key & k) const;
138 
140  virtual boost::optional<Attribute> attribute(const Key &) const = 0;
141 
142  template <typename T>
143  boost::optional<T> attributeAs(const Key& k) const
144  {
145  if (boost::optional<Attribute> attr = attribute(k))
146  return boost::apply_visitor(AttributeConverter<T>(), *attr);
147 
148  return boost::optional<T>();
149  }
150 
151  template <typename Feature>
152  class Wrapper;
153 
154  private:
155  template <typename T>
156  struct AttributeConverter : public boost::static_visitor< boost::optional<T> >
157  {
158  template <typename From>
159  boost::optional<T> operator()(const From& from) const
160  {
161  try
162  {
163  return boost::lexical_cast<T>(from);
164  }
165  catch (boost::bad_lexical_cast&)
166  {
167  return boost::optional<T>();
168  }
169  }
170  };
171  };
172 
173  template <typename Feature>
174  class DtFeatureWrapper : public Feature
175  {
176  public:
177  typedef typename Feature::ForEachFunction ForEachFunction;
178  typedef typename Feature::Attribute Attribute;
179  typedef typename Feature::Key Key;
180 
181  typename Feature::CPtr getPtr() const { return typename Feature::Ptr(clone()); }
182 
183  DtFeatureGeometry geometry() const { return myWrappedFeature->geometry(); }
184 
186  {
187  myWrappedFeature->forEachAttribute(func);
188  }
189 
190  unsigned numberOfAttributes(const typename Key::String& str) const
191  {
192  return myWrappedFeature->numberOfAttributes(str);
193  }
194 
195  boost::optional<Attribute> attribute(const Key& key) const
196  {
197  return myWrappedFeature->attribute(key);
198  }
199 
200  protected:
201  explicit DtFeatureWrapper(const Feature& f)
202  : myWrappedFeature(Feature::GetPtr(f)) { }
203 
204  explicit DtFeatureWrapper(typename Feature::CPtr f)
205  : myWrappedFeature(f) { }
206 
207  virtual DtFeatureWrapper* clone() const = 0;
208 
209  typename Feature::CPtr myWrappedFeature;
210  };
211 
212  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature::Attribute&);
213  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature&);
214  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature::Key&);
215  DT_DLL_features std::ostream& operator<<(std::ostream&, const DtFeature::Key::String&);
216 
224 }

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)