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 
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 
Embedded control libraries.
static const unsigned int buffer_size
char contents[buffer_size]
long append(const char &c)


ecl_devices
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:45