OSVR-Core
GeneralizedTransform.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_GeneralizedTransform_h_GUID_BEA0F0A8_AC82_4093_60F5_34597B06F3A9
26 #define INCLUDED_GeneralizedTransform_h_GUID_BEA0F0A8_AC82_4093_60F5_34597B06F3A9
27 
28 // Internal Includes
29 #include <osvr/Common/Export.h>
31 
32 // Library/third-party includes
33 #include <json/value.h>
34 
35 // Standard includes
36 #include <vector>
37 #include <algorithm>
38 
39 namespace osvr {
40 namespace common {
46  : public util::ContainerWrapper<std::vector<Json::Value>,
47  util::container_policies::iterators,
48  util::container_policies::size> {
49  public:
50 #if 0
51  typedef Json::Value value_type;
54  typedef value_type &reference;
55  typedef value_type const &const_reference;
56  typedef std::vector<value_type> container;
57  typedef container::size_type size_type;
58  typedef container::iterator iterator;
59  typedef container::const_iterator const_iterator;
61  util::container_policies::iterators,
64 
65 #endif
66 
68  OSVR_COMMON_EXPORT GeneralizedTransform();
69 
74  OSVR_COMMON_EXPORT GeneralizedTransform(Json::Value const &transform);
75 
78  OSVR_COMMON_EXPORT void nest(Json::Value const &transform);
79 
82  OSVR_COMMON_EXPORT void wrap(Json::Value const &transform);
83 
85  OSVR_COMMON_EXPORT bool empty() const;
86 
88  OSVR_COMMON_EXPORT Json::Value get() const;
89 
94  OSVR_COMMON_EXPORT Json::Value get(std::string const &leaf) const;
95 
97  void resize(const_iterator newEnd) {
98  container().resize(newEnd - begin());
99  }
100 
101  private:
102  void pushLevelBack(Json::Value level);
103  Json::Value recompose(Json::Value leaf = Json::nullValue) const;
104  };
105 
110  template <typename UnaryPredicate>
112  UnaryPredicate pred) {
113  auto newEnd = std::remove_if(transform.begin(), transform.end(), pred);
114  transform.resize(newEnd);
115  }
116 
117 } // namespace common
118 } // namespace osvr
119 #endif // INCLUDED_GeneralizedTransform_h_GUID_BEA0F0A8_AC82_4093_60F5_34597B06F3A9
Definition: gtest_unittest.cc:5031
OSVR_COMMON_EXPORT bool empty() const
Is this an empty transform?
Definition: GeneralizedTransform.cpp:63
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
Header providing a class template suitable for inheritance that wraps an arbitrary STL-like container...
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
OSVR_COMMON_EXPORT void nest(Json::Value const &transform)
Process the given transform as "inner" to any existing transform.
Definition: GeneralizedTransform.cpp:42
OSVR_COMMON_EXPORT void wrap(Json::Value const &transform)
Wrap a single new layer of transform around the existing ones, if any.
Definition: GeneralizedTransform.cpp:56
Container for easy manipulation of nested transforms.
Definition: GeneralizedTransform.h:45
void resize(const_iterator newEnd)
A shrinking resize.
Definition: GeneralizedTransform.h:97
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
t_< detail::transform_< List, Fun >> transform
Given a list and an alias class, apply the alias class to each element in the list and return the res...
Definition: Transform.h:54
detail::ContainerWrapper_t< Container, Args... > ContainerWrapper
Parent class to inherit from to get a container with some functionality exposed.
Definition: ContainerWrapper.h:232
OSVR_COMMON_EXPORT GeneralizedTransform()
Empty transformation.
Definition: GeneralizedTransform.cpp:37
void remove_if(GeneralizedTransform &transform, UnaryPredicate pred)
Remove levels from a generalized transform as dictated by an arbitrary predicate. ...
Definition: GeneralizedTransform.h:111