PLCnext API Documentation  21.0.0.35466
StaticString.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/Plc/Commons/Gds/StaticStringBase.hpp"
9 namespace Arp { namespace Plc { namespace Commons { namespace Gds
10 {
11 
16 template <uint16 Capacity = 80>
18 {
19 public: // typedefs
21 
22 public: // construction/destruction
24  StaticString(const char8* str = "");
26  StaticString(const StaticString& arg);
28  StaticString& operator=(const StaticString& arg);
29  template <uint16 M>
31  StaticString& operator=(const String& arg);
32  StaticString& operator=(const char8* arg);
34  ~StaticString(void) = default;
35 
36 public: // operators
37 
38 public: // setter/getter operations
39  uint16 GetLength(void)const;
40 
41 public: // operations
42  String ToString(void)const;
43 
44 private: // methods
45  bool IsEmpty(void)const;
46 
47 private: // fields
48  char8 data[Capacity + 1];
49 };
50 
52 // inline methods of class StaticString
53 
54 template <uint16 N>
56  : StaticStringBase(N)
57 {
58  memset(this->data, 0, sizeof(this->data));
59  strncpy(this->data, str, this->capacity);
60  this->length = this->GetLength();
61 }
62 
63 template <uint16 N>
65 {
66  this->capacity = arg.capacity;
67  this->length = arg.length;
68  strncpy(this->data, arg.data, this->capacity);
69 }
70 
71 template <uint16 N>
73 {
74  if (arg.IsEmpty() == false)
75  {
76  memcpy(this->data, arg.GetData(), this->capacity);
77  this->length = arg.length;
78  }
79  return *this;
80 }
81 
82 template <uint16 N>
83 template <uint16 M>
85 {
86  strncpy(this->data, arg.GetData(), this->capacity);
87  this->length = this->GetLength();
88  return *this;
89 }
90 
91 template <uint16 N>
93 {
94  size_t strLength = strlen(arg);
95  if (strLength != 0)
96  {
97  memset(this->data, 0, sizeof(this->data));
98  strncpy(this->data, arg, this->capacity);
99  this->length = this->GetLength();
100  }
101  return *this;
102 }
103 
104 template <uint16 N>
106 {
107  this->operator=(arg.CStr());
108  return *this;
109 }
110 
111 template <uint16 N>
112 inline uint16 StaticString<N>::GetLength(void)const
113 {
114  return (uint16)(strlen(this->data));
115 }
116 
117 template <uint16 N>
119 {
120  return String(this->data);
121 }
122 
123 template <uint16 N>
124 inline bool StaticString<N>::IsEmpty(void)const
125 {
126  if (strlen(this->data) == 0)
127  {
128  return true;
129  }
130  else
131  {
132  return false;
133  }
134 }
135 
136 }}}} // end of namespace Arp::Plc::Commons::Gds
137 
This class represents the counterpart to the data type &#39;IecString&#39;. It&#39;s the C++ data type which can ...
Definition: StaticString.hxx:17
StaticString(const char8 *str="")
Constructs an StaticString instance.
Definition: StaticString.hxx:55
StaticString & operator=(const StaticString &arg)
Assignment operator.
Definition: StaticString.hxx:72
const CharType * CStr() const
Gets the character data of this string.
Definition: BasicString.hxx:1507
Root namespace for the PLCnext API
std::uint16_t uint16
The Arp unsigned integer type of 2 byte size.
Definition: PrimitiveTypes.hpp:31
This class is the base class used for &#39;IecString&#39; and &#39;StaticString&#39;.
Definition: StaticStringBase.hpp:15
~StaticString(void)=default
Destructs this instance and frees all resources.
char char8
The Arp character type of 1 byte size.
Definition: PrimitiveTypes.hpp:47