AUnit  0.5.0
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
FCString.h
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #ifndef AUNIT_FSTRING_H
26 #define AUNIT_FSTRING_H
27 
28 #include <stdint.h>
29 
30 class __FlashStringHelper;
31 
32 namespace aunit {
33 namespace internal {
34 
51 class FCString {
52  public:
53  static const uint8_t kCStringType = 0;
54  static const uint8_t kFStringType = 1;
55 
56  FCString() {}
57 
58  explicit FCString(const char* s):
59  mStringType(kCStringType) {
60  mString.cstring = s;
61  }
62 
63  explicit FCString(const __FlashStringHelper* s):
64  mStringType(kFStringType) {
65  mString.fstring = s;
66  }
67 
68  uint8_t getType() const { return mStringType; }
69 
70  const char* getCString() const { return mString.cstring; }
71 
72  const __FlashStringHelper* getFString() const { return mString.fstring; }
73 
74  private:
75  union {
76  const char* cstring;
77  const __FlashStringHelper* fstring;
78  } mString;
79 
80  uint8_t mStringType;
81 };
82 
83 }
84 }
85 
86 #endif
A union of (const char*) and (const __FlashStringHelper*) with a discriminator.
Definition: FCString.h:51