TypedSpaceInformation.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Neil T. Dantam */
36 
37 #ifndef OMPL_BASE_TYPED_SPACE_INFORMATION_
38 #define OMPL_BASE_TYPED_SPACE_INFORMATION_
39 
40 #include "ompl/base/SpaceInformation.h"
41 #include "ompl/base/ScopedState.h"
42 
43 namespace ompl
44 {
45  namespace base
46  {
47 
48  template<typename SpaceType_>
50  {
51  public:
52 
53  /*--- Type Definitions ---*/
54 
56  typedef SpaceType_ SpaceType;
57 
59  typedef typename SpaceType::StateType StateType;
60 
63 
65  typedef std::shared_ptr<SpaceType> SpacePtr;
66 
68  typedef std::shared_ptr< TypedSpaceInformation<SpaceType> > Ptr;
69 
70 
71  /*--- Constructor ---*/
72 
74  TypedSpaceInformation(const SpacePtr &space) : SpaceInformation(space)
75  {
76  }
77 
78  /*--- Space Accessors ---*/
79 
81  const SpaceType* getTypedStateSpace() const
82  {
83  return getStateSpace()->template as<SpaceType>();
84  }
85 
87  SpaceType* getTypedStateSpace()
88  {
89  return getStateSpace()->template as<SpaceType>();
90  }
91 
92  /*--- State Memory Management ---*/
93 
95  StateType* allocTypedState() const
96  {
97  return this->allocState()->template as<StateType>();
98  }
99 
101  void allocTypedStates(std::vector<StateType *> &states) const
102  {
103  allocStates(states);
104  }
105 
107  void freeTypedState(StateType *state) const
108  {
109  freeState(state);
110  }
111 
113  void freeTypedStates(std::vector<StateType*> &states) const
114  {
115  freeStates(states);
116  }
117 
119  void copyTypedState(StateType *destination, const StateType *source) const
120  {
121  copyState(destination, source);
122  }
123 
125  StateType* cloneTypedState(const StateType *source) const {
126  return this->cloneState()->template as<StateType>();
127  }
128 
129  static StateType* state_as(ompl::base::State *s)
130  {
131  return s->template as<StateType>();
132  }
133 
134  static const StateType* state_as(const ompl::base::State *s)
135  {
136  return s->template as<StateType>();
137  }
138 
139  };
140 
141  }
142 
143 }
144 
145 #endif
void allocStates(std::vector< State * > &states) const
Allocate memory for each element of the array states.
const SpaceType * getTypedStateSpace() const
Definition of a scoped state.
Definition: ScopedState.h:56
TypedSpaceInformation(const SpacePtr &space)
void copyTypedState(StateType *destination, const StateType *source) const
std::shared_ptr< TypedSpaceInformation< SpaceType > > Ptr
State * cloneState(const State *source) const
Clone a state.
void freeTypedState(StateType *state) const
Main namespace. Contains everything in this library.
Definition: Cost.h:42
void copyState(State *destination, const State *source) const
Copy a state to another.
void freeStates(std::vector< State * > &states) const
Free the memory of an array of states.
The base class for space information. This contains all the information about the space planning is d...
StateType * cloneTypedState(const StateType *source) const
Definition of an abstract state.
Definition: State.h:50
const StateSpacePtr & getStateSpace() const
Return the instance of the used state space.
void freeState(State *state) const
Free the memory of a state.
ScopedState< SpaceType > ScopedStateType
State * allocState() const
Allocate memory for a state.
void allocTypedStates(std::vector< StateType * > &states) const
std::shared_ptr< SpaceType > SpacePtr
void freeTypedStates(std::vector< StateType * > &states) const