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 
101  public: ModelState GetModelState(const std::string &_modelName) const;
102 
107  public: bool HasModelState(const std::string &_modelName) const;
108 
113  public: bool IsZero() const;
114 
117  public: void FillSDF(sdf::ElementPtr _sdf);
118 
122  public: virtual void SetWallTime(const common::Time &_time);
123 
126  public: virtual void SetRealTime(const common::Time &_time);
127 
130  public: virtual void SetSimTime(const common::Time &_time);
131 
135  public: WorldState &operator=(const WorldState &_state);
136 
140  public: WorldState operator-(const WorldState &_state) const;
141 
145  public: WorldState operator+(const WorldState &_state) const;
146 
151  public: inline friend std::ostream &operator<<(std::ostream &_out,
152  const gazebo::physics::WorldState &_state)
153  {
154  _out << "<state world_name='" << _state.name << "'>"
155  << "<sim_time>" << _state.simTime << "</sim_time>"
156  << "<wall_time>" << _state.wallTime << "</wall_time>"
157  << "<real_time>" << _state.realTime << "</real_time>";
158 
159  // List all of the inserted models
160  if (_state.insertions.size() > 0)
161  {
162  _out << "<insertions>";
163  for (std::vector<std::string>::const_iterator iter =
164  _state.insertions.begin();
165  iter != _state.insertions.end(); ++iter)
166  {
167  _out << *iter;
168  }
169  _out << "</insertions>";
170  }
171 
172  // List all of the deleted models
173  if (_state.deletions.size() > 0)
174  {
175  _out << "<deletions>";
176  for (std::vector<std::string>::const_iterator iter =
177  _state.deletions.begin();
178  iter != _state.deletions.end(); ++iter)
179  {
180  _out << "<name>" << (*iter) << "</name>";
181  }
182  _out << "</deletions>";
183  }
184 
185  // List the model states
186  for (ModelState_M::const_iterator iter = _state.modelStates.begin();
187  iter != _state.modelStates.end(); ++iter)
188  {
189  _out << iter->second;
190  }
191 
192  _out << "</state>";
193 
194  return _out;
195  }
196 
198  private: ModelState_M modelStates;
199 
202  private: std::vector<std::string> insertions;
203 
206  private: std::vector<std::string> deletions;
207 
209  private: WorldPtr world;
210  };
212  }
213 }
214 #endif