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 #include "physics/State.hh"
29 #include "physics/ModelState.hh"
30 
31 namespace gazebo
32 {
33  namespace physics
34  {
37 
44  class WorldState : public State
45  {
47  public: WorldState();
48 
53  public: explicit WorldState(const WorldPtr _world);
54 
59  public: explicit WorldState(const sdf::ElementPtr _sdf);
60 
62  public: virtual ~WorldState();
63 
68  public: virtual void Load(const sdf::ElementPtr _elem);
69 
72  public: void SetWorld(const WorldPtr _world);
73 
76  public: const std::vector<ModelState> &GetModelStates() const;
77 
82  public: unsigned int GetModelStateCount() const;
83 
91  public: ModelState GetModelState(unsigned int _index) const;
92 
97  public: ModelState GetModelState(const std::string &_modelName) const;
98 
103  public: bool HasModelState(const std::string &_modelName) const;
104 
109  public: bool IsZero() const;
110 
113  public: void FillSDF(sdf::ElementPtr _sdf);
114 
118  public: WorldState &operator=(const WorldState &_state);
119 
123  public: WorldState operator-(const WorldState &_state) const;
124 
128  public: WorldState operator+(const WorldState &_state) const;
129 
134  public: friend std::ostream &operator<<(std::ostream &_out,
135  const gazebo::physics::WorldState &_state)
136  {
137  _out << "<state world_name='" << _state.name << "'>\n";
138  _out << " <sim_time>" << _state.simTime << "</sim_time>\n";
139  _out << " <wall_time>" << _state.wallTime << "</wall_time>\n";
140  _out << " <real_time>" << _state.realTime << "</real_time>\n";
141 
142  // List all of the inserted models
143  if (_state.insertions.size() > 0)
144  {
145  _out << " <insertions>\n";
146  for (std::vector<std::string>::const_iterator iter =
147  _state.insertions.begin();
148  iter != _state.insertions.end(); ++iter)
149  {
150  _out << *iter << "\n";
151  }
152  _out << " </insertions>\n";
153  }
154 
155  // List all of the deleted models
156  if (_state.deletions.size() > 0)
157  {
158  _out << " <deletions>\n";
159  for (std::vector<std::string>::const_iterator iter =
160  _state.deletions.begin();
161  iter != _state.deletions.end(); ++iter)
162  {
163  _out << " <name>" << (*iter) << "</name>\n";
164  }
165  _out << " </deletions>\n";
166  }
167 
168  // List the model states
169  for (std::vector<ModelState>::const_iterator iter =
170  _state.modelStates.begin(); iter != _state.modelStates.end();
171  ++iter)
172  {
173  _out << *iter;
174  }
175 
176  _out << "</state>\n";
177 
178  return _out;
179  }
180 
182  private: std::vector<ModelState> modelStates;
183 
186  private: std::vector<std::string> insertions;
187 
190  private: std::vector<std::string> deletions;
191 
193  private: WorldPtr world;
194  };
196  }
197 }
198 #endif