Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RamStringAdapter.hpp Source File

RamStringAdapter.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
00008 #include <ArduinoJson/Strings/IsString.hpp>
00009 #include <ArduinoJson/Strings/StoragePolicy.hpp>
00010 
00011 namespace ARDUINOJSON_NAMESPACE {
00012 
00013 class RamStringAdapter : public ConstRamStringAdapter {
00014  public:
00015   RamStringAdapter(const char* str) : ConstRamStringAdapter(str) {}
00016 
00017   void copyTo(char* p, size_t n) const {
00018     memcpy(p, _str, n);
00019   }
00020 
00021   typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
00022 };
00023 
00024 template <typename TChar>
00025 inline RamStringAdapter adaptString(const TChar* str) {
00026   return RamStringAdapter(reinterpret_cast<const char*>(str));
00027 }
00028 
00029 inline RamStringAdapter adaptString(char* str) {
00030   return RamStringAdapter(str);
00031 }
00032 
00033 template <typename TChar>
00034 struct IsString<TChar*> {
00035   static const bool value = sizeof(TChar) == 1;
00036 };
00037 
00038 template <>
00039 struct IsString<void*> {
00040   static const bool value = false;
00041 };
00042 
00043 }  // namespace ARDUINOJSON_NAMESPACE