NTRT Simulator  Version: Master
 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 #include "tgSenseable.h"
34 // The C++ Standard Library
35 #include <iostream>
36 #include <vector>
37 
38 // Forward declarations
39 class tgModelVisitor;
40 class tgWorld;
41 class abstractMarker;
42 
49 class tgModel : public tgTaggable, public tgSenseable
50 {
51 public:
52 
57  tgModel();
58 
64  tgModel(const tgTags& tags);
65 
70  virtual ~tgModel();
71 
79  virtual void setup(tgWorld& world);
80 
84  virtual void teardown();
85 
93  virtual void step(double dt);
94 
99  virtual void onVisit(const tgModelVisitor& r) const;
100 
110  void addChild(tgModel* pChild);
111 
118  virtual std::string toString(std::string prefix = "") const;
119 
127  template <typename T>
128  std::vector<T*> find(const tgTagSearch& tagSearch)
129  {
130  return tgCast::find<tgModel, T>(tagSearch, getDescendants());
131  }
132 
140  template <typename T>
141  std::vector<T*> find(const std::string& tagSearch)
142  {
143  return tgCast::find<tgModel, T>(tgTagSearch(tagSearch), getDescendants());
144  }
145 
152  std::vector<tgModel*> getDescendants() const;
153 
154  const std::vector<abstractMarker>& getMarkers() const;
155 
156  void addMarker(abstractMarker a);
157 
164  virtual std::vector<tgSenseable*> getSenseableDescendants() const;
165 
166 private:
167 
169  bool invariant() const;
170 
171 private:
172 
178  std::vector<tgModel*> m_children;
179 
180  std::vector<abstractMarker> m_markers;
181 
182 };
183 
191 std::ostream&
192 operator<<(std::ostream& os, const tgModel& obj);
193 #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:152
void addChild(tgModel *pChild)
Definition: tgModel.cpp:122
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:141
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition: tgModel.h:128
Contains the definition of class tgTaggable.
std::ostream & operator<<(std::ostream &os, const tgModel &obj)
Definition: tgModel.cpp:219
Constains the implementation of mixin class tgSenseable.
virtual std::vector< tgSenseable * > getSenseableDescendants() const
Definition: tgModel.cpp:191
Definition: tgTags.h:44
std::vector< tgModel * > getDescendants() const
Definition: tgModel.cpp:170