All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WorldState.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: A world state
18  * Author: Nate Koenig
19  */
20 
21 #ifndef _WORLDSTATE_HH_
22 #define _WORLDSTATE_HH_
23 
24 #include <string>
25 #include <vector>
26 
27 #include <sdf/sdf.hh>
28 
29 #include "gazebo/physics/State.hh"
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace physics
36  {
39 
47  {
49  public: WorldState();
50 
55  public: explicit WorldState(const WorldPtr _world);
56 
61  public: explicit WorldState(const sdf::ElementPtr _sdf);
62 
64  public: virtual ~WorldState();
65 
70  public: void Load(const WorldPtr _world);
71 
76  public: virtual void Load(const sdf::ElementPtr _elem);
77 
80  public: void SetWorld(const WorldPtr _world);
81 
86  public: ModelState_M GetModelStates(const boost::regex &_regex) const;
87 
90  public: const ModelState_M &GetModelStates() const;
91 
96  public: unsigned int GetModelStateCount() const;
97 
102  public: ModelState GetModelState(const std::string &_modelName) const;
103 
108  public: bool HasModelState(const std::string &_modelName) const;
109 
114  public: bool IsZero() const;
115 
118  public: void FillSDF(sdf::ElementPtr _sdf);
119 
123  public: virtual void SetWallTime(const common::Time &_time);
124 
127  public: virtual void SetRealTime(const common::Time &_time);
128 
131  public: virtual void SetSimTime(const common::Time &_time);
132 
136  public: WorldState &operator=(const WorldState &_state);
137 
141  public: WorldState operator-(const WorldState &_state) const;
142 
146  public: WorldState operator+(const WorldState &_state) const;
147 
152  public: inline friend std::ostream &operator<<(std::ostream &_out,
153  const gazebo::physics::WorldState &_state)
154  {
155  _out << "<state world_name='" << _state.name << "'>"
156  << "<sim_time>" << _state.simTime << "</sim_time>"
157  << "<wall_time>" << _state.wallTime << "</wall_time>"
158  << "<real_time>" << _state.realTime << "</real_time>";
159 
160  // List all of the inserted models
161  if (_state.insertions.size() > 0)
162  {
163  _out << "<insertions>";
164  for (std::vector<std::string>::const_iterator iter =
165  _state.insertions.begin();
166  iter != _state.insertions.end(); ++iter)
167  {
168  _out << *iter;
169  }
170  _out << "</insertions>";
171  }
172 
173  // List all of the deleted models
174  if (_state.deletions.size() > 0)
175  {
176  _out << "<deletions>";
177  for (std::vector<std::string>::const_iterator iter =
178  _state.deletions.begin();
179  iter != _state.deletions.end(); ++iter)
180  {
181  _out << "<name>" << (*iter) << "</name>";
182  }
183  _out << "</deletions>";
184  }
185 
186  // List the model states
187  for (ModelState_M::const_iterator iter = _state.modelStates.begin();
188  iter != _state.modelStates.end(); ++iter)
189  {
190  _out << iter->second;
191  }
192 
193  _out << "</state>";
194 
195  return _out;
196  }
197 
199  private: ModelState_M modelStates;
200 
203  private: std::vector<std::string> insertions;
204 
207  private: std::vector<std::string> deletions;
208 
210  private: WorldPtr world;
211  };
213  }
214 }
215 #endif