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 2012 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 
32 namespace gazebo
33 {
34  namespace physics
35  {
38 
45  class WorldState : public State
46  {
48  public: WorldState();
49 
54  public: explicit WorldState(const WorldPtr _world);
55 
60  public: explicit WorldState(const sdf::ElementPtr _sdf);
61 
63  public: virtual ~WorldState();
64 
69  public: void Load(const WorldPtr _world);
70 
75  public: virtual void Load(const sdf::ElementPtr _elem);
76 
79  public: void SetWorld(const WorldPtr _world);
80 
85  public: ModelState_M GetModelStates(const boost::regex &_regex) const;
86 
89  public: const ModelState_M &GetModelStates() const;
90 
95  public: unsigned int GetModelStateCount() const;
96 
98  public: ModelState GetModelState(unsigned int _index) const
99  GAZEBO_DEPRECATED(1.7);
100 
105  public: ModelState GetModelState(const std::string &_modelName) const;
106 
111  public: bool HasModelState(const std::string &_modelName) const;
112 
117  public: bool IsZero() const;
118 
121  public: void FillSDF(sdf::ElementPtr _sdf);
122 
126  public: virtual void SetWallTime(const common::Time &_time);
127 
130  public: virtual void SetRealTime(const common::Time &_time);
131 
134  public: virtual void SetSimTime(const common::Time &_time);
135 
139  public: WorldState &operator=(const WorldState &_state);
140 
144  public: WorldState operator-(const WorldState &_state) const;
145 
149  public: WorldState operator+(const WorldState &_state) const;
150 
155  public: inline friend std::ostream &operator<<(std::ostream &_out,
156  const gazebo::physics::WorldState &_state)
157  {
158  _out << "<state world_name='" << _state.name << "'>"
159  << "<sim_time>" << _state.simTime << "</sim_time>"
160  << "<wall_time>" << _state.wallTime << "</wall_time>"
161  << "<real_time>" << _state.realTime << "</real_time>";
162 
163  // List all of the inserted models
164  if (_state.insertions.size() > 0)
165  {
166  _out << "<insertions>";
167  for (std::vector<std::string>::const_iterator iter =
168  _state.insertions.begin();
169  iter != _state.insertions.end(); ++iter)
170  {
171  _out << *iter;
172  }
173  _out << "</insertions>";
174  }
175 
176  // List all of the deleted models
177  if (_state.deletions.size() > 0)
178  {
179  _out << "<deletions>";
180  for (std::vector<std::string>::const_iterator iter =
181  _state.deletions.begin();
182  iter != _state.deletions.end(); ++iter)
183  {
184  _out << "<name>" << (*iter) << "</name>";
185  }
186  _out << "</deletions>";
187  }
188 
189  // List the model states
190  for (ModelState_M::const_iterator iter = _state.modelStates.begin();
191  iter != _state.modelStates.end(); ++iter)
192  {
193  _out << iter->second;
194  }
195 
196  _out << "</state>";
197 
198  return _out;
199  }
200 
202  private: ModelState_M modelStates;
203 
206  private: std::vector<std::string> insertions;
207 
210  private: std::vector<std::string> deletions;
211 
213  private: WorldPtr world;
214  };
216  }
217 }
218 #endif