character_buffer.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include "../../../include/ecl/devices/detail/character_buffer.hpp"
13 
14 /*****************************************************************************
15 ** Namespaces
16 *****************************************************************************/
17 
18 namespace ecl {
19 namespace devices {
20 
21 /*****************************************************************************
22 ** Implementation [CharBuffer]
23 *****************************************************************************/
24 
25 
26 bool CharBuffer::full() const {
27  if ( fill_point_marker == buffer_size ) {
28  return true;
29  } else {
30  return false;
31  }
32 }
33 
34 long CharBuffer::append(const char& c) {
35 
36  if ( full() ) {
37  return 0;
38  } else {
41  return 1;
42  }
43 }
44 
45 long CharBuffer::append(const char* s, unsigned long n) {
46 
47  if ( n <= remaining() ) {
48  memcpy(&contents[fill_point_marker], s, n);
49  fill_point_marker += n;
50  return n;
51  } else {
52  unsigned int num_to_copy = remaining();
53  memcpy(&contents[fill_point_marker], s, num_to_copy);
54  fill_point_marker += num_to_copy;
55  return num_to_copy;
56  }
57 }
58 
59 void CharBuffer::clear() {
61 }
62 
63 
64 /*****************************************************************************
65 ** Implementation [CharStringBuffer]
66 *****************************************************************************/
67 
68 bool CharStringBuffer::full() const {
69  if ( fill_point_marker == buffer_size ) {
70  return true;
71  } else {
72  return false;
73  }
74 }
75 
76 long CharStringBuffer::append(const char& c) {
77 
78  if ( full() ) {
79  return 0;
80  } else {
83  return 1;
84  }
85 }
86 
87 long CharStringBuffer::append(const char* s, unsigned long n) {
88 
89  if ( n <= remaining() ) {
90  memcpy(&contents[fill_point_marker], s, n);
91  fill_point_marker += n;
92  return n;
93  } else {
94  unsigned int num_to_copy = remaining();
95  memcpy(&contents[fill_point_marker], s, num_to_copy);
96  fill_point_marker += num_to_copy;
97  return num_to_copy;
98  }
99 }
100 
102  fill_point_marker = 0;
103 }
104 
105 const char* CharStringBuffer::c_str() {
106  contents[fill_point_marker] = '\0';
107  return &contents[0];
108 }
109 
110 
111 } // namespace devices
112 } // namespace ecl
113 
ecl::devices::CharStringBuffer::remaining
unsigned int remaining()
Definition: character_buffer.hpp:109
ecl::devices::CharBuffer::fill_point_marker
unsigned int fill_point_marker
Definition: character_buffer.hpp:84
ecl::devices::CharStringBuffer::contents
char contents[buffer_size+1]
Definition: character_buffer.hpp:121
ecl::devices::CharStringBuffer::fill_point_marker
unsigned int fill_point_marker
Definition: character_buffer.hpp:120
ecl::devices::CharBuffer::buffer_size
static const unsigned int buffer_size
Definition: character_buffer.hpp:64
ecl::devices::CharBuffer::clear
void clear()
Definition: character_buffer.cpp:67
ecl::devices::CharBuffer::full
bool full() const
Definition: character_buffer.cpp:34
ecl::devices::CharStringBuffer::full
bool full() const
Definition: character_buffer.cpp:76
ecl::devices::CharBuffer::append
long append(const char &c)
Definition: character_buffer.cpp:42
ecl::devices::CharStringBuffer::c_str
const char * c_str()
Definition: character_buffer.cpp:113
ecl::devices::CharStringBuffer::clear
void clear()
Definition: character_buffer.cpp:109
ecl::devices::CharStringBuffer::buffer_size
static const unsigned int buffer_size
Definition: character_buffer.hpp:98
ecl::devices::CharStringBuffer::append
long append(const char &c)
Definition: character_buffer.cpp:84
ecl::devices::CharBuffer::contents
char contents[buffer_size]
Definition: character_buffer.hpp:85
ecl
Embedded control libraries.
ecl::devices::CharBuffer::remaining
unsigned int remaining()
Definition: character_buffer.hpp:72


ecl_devices
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:45