byte_array.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2011, Southwest Research Institute
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *       * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *       * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *       * Neither the name of the Southwest Research Institute, nor the names
00016  *       of its contributors may be used to endorse or promote products derived
00017  *       from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef BYTE_ARRAY_H
00033 #define BYTE_ARRAY_H
00034 
00035 #ifdef ROS
00036 
00037 #include "simple_message/shared_types.h"
00038 
00039 #endif
00040 
00041 #ifdef MOTOPLUS
00042 
00043 #include "shared_types.h"
00044 
00045 #endif
00046 
00047 #include "string.h"
00048 
00049 namespace industrial
00050 {
00051 namespace simple_serialize
00052 {
00053 // Class declaration required for function prototypes below
00054 class SimpleSerialize;
00055 }
00056 }
00057 
00058 namespace industrial
00059 {
00060 namespace byte_array
00061 {
00062 
00083 class ByteArray
00084 {
00085 public:
00086 
00087   // Provides SimpleSerialize access to byte array internals
00088   friend class SimpleSerialize;
00089 
00096   ByteArray(void);
00097 
00102   ~ByteArray(void);
00103 
00110   void init();
00111 
00125   bool init(const char* buffer, const industrial::shared_types::shared_int byte_size);
00126 
00136   void copyFrom(ByteArray & buffer);
00137 
00146   bool load(industrial::shared_types::shared_bool value);
00147 
00158   bool load(industrial::shared_types::shared_real value);
00159 
00169   bool load(industrial::shared_types::shared_int value);
00170 
00179   bool load(industrial::simple_serialize::SimpleSerialize &value);
00180 
00189   bool load(ByteArray &value);
00190 
00201   bool load(void* value, const industrial::shared_types::shared_int byte_size);
00202 
00210   bool unload(industrial::shared_types::shared_bool &value);
00211 
00220   bool unload(industrial::shared_types::shared_real &value);
00221 
00230   bool unload(industrial::shared_types::shared_int &value);
00231 
00239   bool unload(industrial::simple_serialize::SimpleSerialize &value);
00240 
00250   bool unload(ByteArray &value, const industrial::shared_types::shared_int byte_size);
00251 
00261   bool unload(void* value, const industrial::shared_types::shared_int byteSize);
00262 
00273   bool unloadFront(industrial::shared_types::shared_real &value);
00274 
00285   bool unloadFront(industrial::shared_types::shared_int &value);
00286 
00298   bool unloadFront(void* value, const industrial::shared_types::shared_int byteSize);
00299 
00312   char* getRawDataPtr();
00313 
00319   unsigned int getBufferSize();
00320 
00326   unsigned int getMaxBufferSize();
00327 
00335   static bool isByteSwapEnabled();
00336 
00337 private:
00346   static const industrial::shared_types::shared_int MAX_SIZE = 1024;
00347 
00351   char buffer_[MAX_SIZE];
00352 
00356   industrial::shared_types::shared_int buffer_size_;
00357 
00358 #ifdef BYTE_SWAPPING
00359 
00366   void swap(void *value, industrial::shared_types::shared_int byteSize);
00367 #endif
00368 
00376   bool setBufferSize(const industrial::shared_types::shared_int size);
00377 
00385   bool extendBufferSize(const industrial::shared_types::shared_int size);
00386 
00394   bool shortenBufferSize(industrial::shared_types::shared_int size);
00395 
00403   char* getLoadPtr();
00404 
00413   char* getUnloadPtr(const industrial::shared_types::shared_int num_bytes);
00414 
00415 };
00416 
00417 } // namespace industrial
00418 } // namespace byte_array
00419 
00420 #endif //BYTE_ARRAY_H


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Oct 6 2014 00:54:17