character_buffer.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include "../../../include/ecl/devices/detail/character_buffer.hpp"
00013 
00014 /*****************************************************************************
00015 ** Namespaces
00016 *****************************************************************************/
00017 
00018 namespace ecl {
00019 namespace devices {
00020 
00021 /*****************************************************************************
00022 ** Implementation [CharBuffer]
00023 *****************************************************************************/
00024 
00025 
00026 bool CharBuffer::full() const {
00027         if ( fill_point_marker == buffer_size ) {
00028                 return true;
00029         } else {
00030                 return false;
00031         }
00032 }
00033 
00034 long CharBuffer::append(const char& c) {
00035 
00036         if ( full() ) {
00037                 return 0;
00038         } else {
00039                 contents[fill_point_marker] = c;
00040                 fill_point_marker++;
00041                 return 1;
00042         }
00043 }
00044 
00045 long CharBuffer::append(const char* s, unsigned long n) {
00046 
00047         if ( n <= remaining() ) {
00048                 memcpy(&contents[fill_point_marker], s, n);
00049                 fill_point_marker += n;
00050                 return n;
00051         } else {
00052                 unsigned int num_to_copy = remaining();
00053                 memcpy(&contents[fill_point_marker], s, num_to_copy);
00054                 fill_point_marker += num_to_copy;
00055                 return num_to_copy;
00056         }
00057 }
00058 
00059 void CharBuffer::clear() {
00060         fill_point_marker = 0;
00061 }
00062 
00063 
00064 /*****************************************************************************
00065 ** Implementation [CharStringBuffer]
00066 *****************************************************************************/
00067 
00068 bool CharStringBuffer::full() const {
00069         if ( fill_point_marker == buffer_size ) {
00070                 return true;
00071         } else {
00072                 return false;
00073         }
00074 }
00075 
00076 long CharStringBuffer::append(const char& c) {
00077 
00078         if ( full() ) {
00079                 return 0;
00080         } else {
00081                 contents[fill_point_marker] = c;
00082                 fill_point_marker++;
00083                 return 1;
00084         }
00085 }
00086 
00087 long CharStringBuffer::append(const char* s, unsigned long n) {
00088 
00089         if ( n <= remaining() ) {
00090                 memcpy(&contents[fill_point_marker], s, n);
00091                 fill_point_marker += n;
00092                 return n;
00093         } else {
00094                 unsigned int num_to_copy = remaining();
00095                 memcpy(&contents[fill_point_marker], s, num_to_copy);
00096                 fill_point_marker += num_to_copy;
00097                 return num_to_copy;
00098         }
00099 }
00100 
00101 void CharStringBuffer::clear() {
00102         fill_point_marker = 0;
00103 }
00104 
00105 const char* CharStringBuffer::c_str() {
00106         contents[fill_point_marker] = '\0';
00107         return &contents[0];
00108 }
00109 
00110 
00111 } // namespace devices
00112 } // namespace ecl
00113 


ecl_devices
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:18:03