gusimplewhiteboard
FilteredArrayOneDimSonar.hpp
Go to the documentation of this file.
1
2/*
3 * FilteredArrayOneDimSonar.h
4 * gusimplewhiteboard
5 *
6 * Created by Vlad Estivill-Castro on 18/06/2014..
7 * Copyright (c) 2013, 2014 Vlad Estivill-Castro. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Rene Hexel.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60
61
62/****************** I M P O R T A N T */
63/* is <class_name>_DEFINED */
64/***************************************/
65
66#ifndef FilteredArrayOneDimSonar_DEFINED
67#define FilteredArrayOneDimSonar_DEFINED
68
69#include <cstdlib>
70#include <sstream>
71#include <gu_util.h>
72
74
76
77namespace guWhiteboard {
82{
83#define SEPARATOR_IS_COMMA ','
84#define SEPARATOR_IS_COLON ':'
85#define IS_VISIBLE_ID 'I'
86#define LEFT_ID 'L'
87#define RIGHT_ID 'R'
88
89public:
92 { /* */ }
93
96 {
97 _objects[landmarkType]=obj;
98 }
99
100
101
104 {
105#ifdef DEBUG
106 //assert(sizeof(*this) == sizeof(wb_arrayoffilteredsonarobjects));
107#endif
108 memcpy(this, &other, sizeof(other));
109 }
110
113 {
114 memcpy(this, &other, sizeof(other));
115
116 return *this;
117 }
118
120 //class FilteredArrayOneDimSonar *objects() { return _objects; }
121
122
126 void set_objects(const class FilteredArrayOneDimSonar *objects)
127 {
128 memcpy(_objects, objects, sizeof(_objects));
129 }
130
132 void set_object(const class FilteredOneDimSonar &obj, enum FilteredSonarObjectType landmarkType = FSLeft)
133 {
134 wb_arrayoffilteredsonarobjects::set_objects(obj, landmarkType);
135 }
136
139 {
140 return objects(landmarkType);
141 }
142#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
143
144
146 FilteredArrayOneDimSonar(const std::string &names) { from_string(names); }
147
149 FilteredArrayOneDimSonar(const char *names) { from_string(names); }
150
152 /* The two elements of the array are printed, distinguished by a starting
153 * identification L: (for Left) and R: (for right)
154 * Then the string of a FilteredOneDimSonar
155 */
156
157 std::string description()
158 {
159 std::ostringstream ss;
160 for ( int i =FSLeft; i< FSO_NUM_OBJECTS; i++ )
161 {
163 switch (landmarkType )
164 {
165 case FSLeft : ss << LEFT_ID<<SEPARATOR_IS_COLON;
166 break;
167 case FSRight : ss << RIGHT_ID<<SEPARATOR_IS_COLON ;
168 break;
169 case FSO_NUM_OBJECTS : mipal_warn( "ERROR:");
170 break;
171 }// switch
172 ss << get_object(landmarkType).description();
173 } //for
174 return ss.str();
175 }
176
178 void from_string(const std::string &str)
179 {
180 std::istringstream iss(str);
181 std::string token;
182
183 std::string left (1,LEFT_ID); left+=SEPARATOR_IS_COLON;
184 std::string right (1,RIGHT_ID); right+=SEPARATOR_IS_COLON;
185
186 std::size_t found = str.find(left);
187 if (std::string::npos!=found )
188 { std::string strForLeft=str.substr (found+left.size());
189 FilteredOneDimSonar theLeft(strForLeft);
190 set_object(theLeft,FSLeft);
191 }
192
193 found = str.find(right);
194 if (std::string::npos!=found )
195 { std::string strForRight=str.substr (found+right.size());
196 FilteredOneDimSonar theRight(strForRight);
197 set_object(theRight,FSRight );
198 }
199
200
201 }
202#endif // WHITEBOARD_POSTER_STRING_CONVERSION
203
204
205};
206} // namespace
207
208
209#endif // FilteredArrayOneDimSonar_h
#define SEPARATOR_IS_COLON
#define LEFT_ID
#define RIGHT_ID
Class for for the array of sonar messages, LEFT and RIGHT.
FilteredArrayOneDimSonar(const class FilteredOneDimSonar &obj, enum FilteredSonarObjectType landmarkType=FSLeft)
constructor with one setter
std::string description()
convert to a string; string serialization
void set_object(const class FilteredOneDimSonar &obj, enum FilteredSonarObjectType landmarkType=FSLeft)
single vision object setter
FilteredArrayOneDimSonar(const FilteredArrayOneDimSonar &other)
copy constructor
FilteredOneDimSonar get_object(enum FilteredSonarObjectType landmarkType=FSLeft)
single vision object setter
void from_string(const std::string &str)
build from string
FilteredArrayOneDimSonar(const char *names)
const char * constructor
void set_objects(const class FilteredArrayOneDimSonar *objects)
property getter
FilteredArrayOneDimSonar & operator=(const FilteredArrayOneDimSonar &other)
copy assignment operator
FilteredArrayOneDimSonar(const std::string &names)
string constructor
Class for for one filtered sonar message.
std::string description() const
convert to a string; string serialization
/file APM_Interface.h
c array for filtered sonar transmitter objects
FilteredSonarObjectType
enum for filtered sonar transmitters
@ FSO_NUM_OBJECTS
number of different kind SONAR of objects