NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgModel.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
19 #ifndef TG_MODEL_H
20 #define TG_MODEL_H
21 
29 // This application
30 #include "tgCast.h"
31 #include "tgTaggable.h"
32 #include "tgTagSearch.h"
33 // The C++ Standard Library
34 #include <iostream>
35 #include <vector>
36 
37 // Forward declarations
38 class tgModelVisitor;
39 class tgWorld;
40 class abstractMarker;
41 
46 class tgModel : public tgTaggable
47 {
48 public:
49 
54  tgModel();
55 
61  tgModel(const tgTags& tags);
62 
67  virtual ~tgModel();
68 
76  virtual void setup(tgWorld& world);
77 
81  virtual void teardown();
82 
90  virtual void step(double dt);
91 
96  virtual void onVisit(const tgModelVisitor& r) const;
97 
107  void addChild(tgModel* pChild);
108 
115  virtual std::string toString(std::string prefix = "") const;
116 
124  template <typename T>
125  std::vector<T*> find(const tgTagSearch& tagSearch)
126  {
127  return tgCast::find<tgModel, T>(tagSearch, getDescendants());
128  }
129 
137  template <typename T>
138  std::vector<T*> find(const std::string& tagSearch)
139  {
140  return tgCast::find<tgModel, T>(tgTagSearch(tagSearch), getDescendants());
141  }
142 
149  std::vector<tgModel*> getDescendants() const;
150 
151  const std::vector<abstractMarker>& getMarkers() const;
152 
153  void addMarker(abstractMarker a);
154 
155 private:
156 
158  bool invariant() const;
159 
160 private:
161 
167  std::vector<tgModel*> m_children;
168 
169  std::vector<abstractMarker> m_markers;
170 
171 };
172 
180 std::ostream&
181 operator<<(std::ostream& os, const tgModel& obj);
182 #endif
Contains the definition of class tgTagSearch.
virtual void teardown()
Definition: tgModel.cpp:68
virtual void setup(tgWorld &world)
Definition: tgModel.cpp:57
virtual std::string toString(std::string prefix="") const
Definition: tgModel.cpp:154
void addChild(tgModel *pChild)
Definition: tgModel.cpp:124
virtual void step(double dt)
Definition: tgModel.cpp:84
Utility class for class casting and filtering collections by type.
virtual ~tgModel()
Definition: tgModel.cpp:45
virtual void onVisit(const tgModelVisitor &r) const
Definition: tgModel.cpp:107
tgModel()
Definition: tgModel.cpp:33
std::vector< T * > find(const std::string &tagSearch)
Definition: tgModel.h:138
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition: tgModel.h:125
Contains the definition of class tgTaggable.
std::ostream & operator<<(std::ostream &os, const tgModel &obj)
Definition: tgModel.cpp:204
Definition: tgTags.h:44
std::vector< tgModel * > getDescendants() const
Definition: tgModel.cpp:172