OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
RecomposeTransform.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_RecomposeTransform_h_GUID_4CA04427_C4DC_4898_8938_D735D4A6C056
26 #define INCLUDED_RecomposeTransform_h_GUID_4CA04427_C4DC_4898_8938_D735D4A6C056
27 
28 // Internal Includes
30 
31 // Library/third-party includes
32 #include <json/value.h>
33 
34 // Standard includes
35 #include <vector>
36 
40 template <typename Predicate>
41 inline Json::Value remove_levels_if(Json::Value input, Predicate p) {
42  namespace keys = osvr::common::routing_keys;
43  std::vector<Json::Value> levels;
44  Json::Value current = input;
45  while (current.isMember(keys::child()) &&
46  current[keys::child()].isObject()) {
47  if (!p(current)) {
48  levels.push_back(current);
49  }
50  current = current[keys::child()];
51  }
52  while (levels.size() > 0) {
53  Json::Value next = levels.back();
54  levels.pop_back();
55  next[keys::child()] = current;
56  current = next;
57  }
58  return current;
59 }
60 
61 #endif // INCLUDED_RecomposeTransform_h_GUID_4CA04427_C4DC_4898_8938_D735D4A6C056
Json::Value remove_levels_if(Json::Value input, Predicate p)
Goes through your transform, starting at the outermost layer, and keeping and re-composing only the l...