simple_string.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * FSRobo-R Package BSDL
3 * ---------
4 * Copyright (C) 2019 FUJISOFT. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *********************************************************************/
28 
29 #include <string>
33 
35 
36 namespace fsrobo_r_driver
37 {
38 namespace simple_message
39 {
40 namespace simple_string
41 {
42 
44 {
45  this->init();
46 }
47 
49 {
50 }
51 
53 {
54  this->init("");
55 }
56 
57 void SimpleString::init(string str)
58 {
59  this->setString(str);
60 }
61 
63 {
64  this->setString(src.getString());
65 }
66 
68 {
69  bool rslt = this->string_ == rhs.string_;
70 
71  return rslt;
72 }
73 
75 {
76  LOG_COMM("Executing SimpleString load");
77 
78  shared_int size = this->getStringSize();
79 
80  char *str = new char[size + 1];
81  str[size] = '\0';
82  this->string_.copy(str, size);
83 
84  if (!buffer->load(str, size)) {
85  LOG_ERROR("Failed to load SimpleString data");
86  delete[] str;
87  return false;
88  }
89  delete[] str;
90 
91  if (!buffer->load(size))
92  {
93  LOG_ERROR("Failed to load SimpleString size");
94  return false;
95  }
96 
97  LOG_COMM("SimpleString data successfully loaded");
98  return true;
99 }
100 
102 {
103  LOG_COMM("Executing SimpleString unload");
104 
105  shared_int size;
106 
107  //if (!buffer->unload(this->result_code_))
108  if (!buffer->unload(size))
109  {
110  LOG_ERROR("Failed to unload SimpleString size");
111  return false;
112  }
113 
114  char *str = new char[size + 1];
115  str[size] = '\0';
116  if (!buffer->unload(str, size)) {
117  LOG_ERROR("Failed to unload SimpleString size");
118  delete[] str;
119  return false;
120  }
121  this->string_ = str;
122 
123  delete[] str;
124 
125  LOG_COMM("SimpleString data successfully unloaded");
126 
127  return true;
128 }
129 
130 }
131 }
132 }
string getString() const
Returns the string data.
void copyFrom(SimpleString &src)
Copies the passed in value.
#define LOG_COMM(format,...)
bool load(industrial::shared_types::shared_bool value)
void setString(string str)
Sets the string data.
Definition: simple_string.h:95
#define LOG_ERROR(format,...)
industrial::shared_types::shared_int getStringSize() const
Returns the string size.
void init()
Initializes a empty motion control reply.
Class encapsulated set io reply data. These messages are sent by the FSRobo-R controller in response ...
Definition: simple_string.h:61
bool unload(industrial::shared_types::shared_bool &value)
bool load(industrial::byte_array::ByteArray *buffer)
bool unload(industrial::byte_array::ByteArray *buffer)
bool operator==(SimpleString &rhs)
== operator implementation


fsrobo_r_driver
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:29