KJB
psi_start_state.h
Go to the documentation of this file.
1 /* \$Id: psi_start_state.h 10707 2011-09-29 20:05:56Z predoehl \$ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== }}}*/
19
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 #ifndef PSI_V1_START_STATE_H
22 #define PSI_V1_START_STATE_H
23
24 #include <psi_cpp/psi_units.h>
25 #include <string>
26 #include <sstream>
27
28 namespace kjb
29 {
30 namespace psi
31 {
32
34 {
36  x(),
37  y(),
38  theta()
39  {
40  }
41
42  Start_state(double in_x, double in_y, double in_theta) :
43  x(in_x),
44  y(in_y),
45  theta(in_theta)
46  {}
47
48  double x;
49  double y;
50  double theta;
51
52  double operator[](size_t i) const
53  {
54  switch(i)
55  {
56  case 0: return x;
57  case 1: return y;
58  case 2: return theta;
60  }
61  }
62
63  double& operator[](size_t i)
64  {
65  switch(i)
66  {
67  case 0: return x;
68  case 1: return y;
69  case 2: return theta;
71  }
72  }
73
74  static size_t size() {return 3;}
75
76  static Unit_type get_units(size_t i)
77  {
78  switch(i)
79  {
80  case 0: return SPACIAL_UNIT;
81  case 1: return SPACIAL_UNIT;
82  case 2: return ANGLE_UNIT;
83  default : KJB_THROW_2(kjb::Illegal_argument, "Unknown unit type.");
84  }
85  }
86 };
87
88 inline std::ostream& operator<<(std::ostream& ost, const Start_state& start_state)
89 {
90  ost << start_state.x << " ";
91  ost << start_state.y << " ";
92  ost << start_state.theta;
93
94  return ost;
95 }
96
97 inline std::istream& operator>>(std::istream& ist, Start_state& start_state)
98 {
99  using namespace std;
100
101  ist >> start_state.x;
102  ist >> start_state.y;
103  ist >> start_state.theta;
104
105  return ist;
106 }
107
108 inline Start_state parse_cli_start_state(const std::string& str)
109 {
110  std::istringstream ist(str);
111  Start_state start;
112  ist >> start;
113  return start;
114 }
115
116 } // namespace psi
117 } // namespace kjb
118 #endif
static size_t size()
Definition: psi_start_state.h:74
double & operator[](size_t i)
Definition: psi_start_state.h:63
std::ostream & operator<<(std::ostream &ost, const Action &action)
serialize an action
Definition: psi_action.cpp:333
double y
Definition: psi_start_state.h:49
Object thrown when an index argument exceeds the size of a container.
Definition: l_exception.h:399
std::istream & operator>>(std::istream &ist, Action &action)
unserialize an action
Definition: psi_action.cpp:346
Unit_type
Definition: psi_units.h:30
Start_state(double in_x, double in_y, double in_theta)
Definition: psi_start_state.h:42
double x
Definition: psi_start_state.h:48
#define KJB_THROW(ex)
Definition: l_exception.h:46
double theta
Definition: psi_start_state.h:50
Definition: psi_start_state.h:33
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
Start_state()
Definition: psi_start_state.h:35
static Unit_type get_units(size_t i)
Definition: psi_start_state.h:76
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Definition: psi_units.h:31
Definition: psi_units.h:34
Start_state parse_cli_start_state(const std::string &str)
Definition: psi_start_state.h:108
double operator[](size_t i) const
Definition: psi_start_state.h:52