AceCommon  1.4.5
Arduino library for low-level common functions and features with no external dependencies
FlashString.h
1 /*
2 MIT License
3 
4 Copyright (c) 2021 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 ACE_COMMON_FLASH_STRING_H
26 #define ACE_COMMON_FLASH_STRING_H
27 
28 #include <Arduino.h>
29 
30 namespace ace_common {
31 
49 class FlashString {
50  public:
52  FlashString(const __FlashStringHelper* p)
53  : fsp((const char*) p) {}
54 
56  FlashString(const FlashString&) = default;
57 
59  FlashString& operator=(const FlashString&) = default;
60 
62  char operator*() const { return (char) pgm_read_byte(fsp); }
63 
65  char operator[](size_t i) const { return *(fsp + i); }
66 
87  operator const void*() const {
88  return (const void*) fsp;
89  }
90 
92  explicit operator const __FlashStringHelper*() const {
93  return (const __FlashStringHelper*) fsp;
94  }
95 
98  return (const __FlashStringHelper*) ++fsp;
99  }
100 
103  return (const __FlashStringHelper*) fsp++;
104  }
105 
108  return (const __FlashStringHelper*) --fsp;
109  }
110 
113  return (const __FlashStringHelper*) fsp--;
114  }
115 
116  private:
117 
118  const char* fsp;
119 };
120 
121 } // ace_common
122 
123 #endif
ace_common::FlashString::operator--
FlashString operator--(int)
Post-decrement.
Definition: FlashString.h:112
ace_common::FlashString::operator--
FlashString operator--()
Pre-decrement.
Definition: FlashString.h:107
ace_common::FlashString::FlashString
FlashString(const __FlashStringHelper *p)
Constructor, with implicit conversion.
Definition: FlashString.h:52
ace_common::FlashString::operator*
char operator*() const
Dereference operator.
Definition: FlashString.h:62
ace_common::FlashString
A thin wrapper around a (const __FlashStringHelper*) so that it acts exactly like a (const char*) wit...
Definition: FlashString.h:49
ace_common::FlashString::operator++
FlashString operator++(int)
Post-increment.
Definition: FlashString.h:102
ace_common::FlashString::operator++
FlashString operator++()
Pre-increment.
Definition: FlashString.h:97
ace_common::FlashString::operator[]
char operator[](size_t i) const
Array dereference operator.
Definition: FlashString.h:65
ace_common::FlashString::operator=
FlashString & operator=(const FlashString &)=default
Default assignment operator.