mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /*
mbedAustin 11:cada08fc8a70 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
mbedAustin 11:cada08fc8a70 3 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 4 * Licensed under the Apache License, Version 2.0 (the License); you may
mbedAustin 11:cada08fc8a70 5 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 6 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 7 *
mbedAustin 11:cada08fc8a70 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 9 *
mbedAustin 11:cada08fc8a70 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 13 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 14 * limitations under the License.
mbedAustin 11:cada08fc8a70 15 */
mbedAustin 11:cada08fc8a70 16 #include <stddef.h> // size_t
mbedAustin 11:cada08fc8a70 17 #include <stdexcept>
mbedAustin 11:cada08fc8a70 18
mbedAustin 11:cada08fc8a70 19 class Test_M2MString;
mbedAustin 11:cada08fc8a70 20
mbedAustin 11:cada08fc8a70 21 namespace m2m
mbedAustin 11:cada08fc8a70 22 {
mbedAustin 11:cada08fc8a70 23
mbedAustin 11:cada08fc8a70 24 /** @brief Simple C++ string class, used as replacement for
mbedAustin 11:cada08fc8a70 25 std::string.
mbedAustin 11:cada08fc8a70 26 */
mbedAustin 11:cada08fc8a70 27 class String
mbedAustin 11:cada08fc8a70 28 {
mbedAustin 11:cada08fc8a70 29 char* p; ///< The data
mbedAustin 11:cada08fc8a70 30 size_t allocated_; ///< The allocated memory size (including trailing NULL)
mbedAustin 11:cada08fc8a70 31 size_t size_; ///< The currently used memory size (excluding trailing NULL)
mbedAustin 11:cada08fc8a70 32
mbedAustin 11:cada08fc8a70 33 public:
mbedAustin 11:cada08fc8a70 34 typedef size_t size_type;
mbedAustin 11:cada08fc8a70 35 static const size_type npos;
mbedAustin 11:cada08fc8a70 36
mbedAustin 11:cada08fc8a70 37 String();
mbedAustin 11:cada08fc8a70 38 virtual ~String();
mbedAustin 11:cada08fc8a70 39 String(const String&);
mbedAustin 11:cada08fc8a70 40 String(const char*);
mbedAustin 11:cada08fc8a70 41
mbedAustin 11:cada08fc8a70 42 String& operator=(const char*);
mbedAustin 11:cada08fc8a70 43 String& operator=(const String&);
mbedAustin 11:cada08fc8a70 44
mbedAustin 11:cada08fc8a70 45 String& operator+=(const String&);
mbedAustin 11:cada08fc8a70 46 String& operator+=(const char*);
mbedAustin 11:cada08fc8a70 47 String& operator+=(char);
mbedAustin 11:cada08fc8a70 48 void push_back(char);
mbedAustin 11:cada08fc8a70 49
mbedAustin 11:cada08fc8a70 50 //No need for this += is
mbedAustin 11:cada08fc8a70 51 //friend String operator+(const String& lhs, const String& rhs);
mbedAustin 11:cada08fc8a70 52
mbedAustin 11:cada08fc8a70 53 bool operator==(const char*) const;
mbedAustin 11:cada08fc8a70 54 bool operator==(const String&) const;
mbedAustin 11:cada08fc8a70 55
mbedAustin 11:cada08fc8a70 56 void clear(); // set string to empty string (memory remains reserved)
mbedAustin 11:cada08fc8a70 57
mbedAustin 11:cada08fc8a70 58 size_type size() const { return size_; } ///< size without terminating NULL
mbedAustin 11:cada08fc8a70 59 size_type length() const { return size_; } ///< as size()
mbedAustin 11:cada08fc8a70 60
mbedAustin 11:cada08fc8a70 61 /// size if fully used
mbedAustin 11:cada08fc8a70 62 size_type capacity() const { return allocated_-1; }
mbedAustin 11:cada08fc8a70 63
mbedAustin 11:cada08fc8a70 64 bool empty() const { return size_ == 0; }
mbedAustin 11:cada08fc8a70 65
mbedAustin 11:cada08fc8a70 66 const char* c_str() const { return p; } ///< raw data
mbedAustin 11:cada08fc8a70 67
mbedAustin 11:cada08fc8a70 68 /** Reserve internal string memory so that n characters can be put into the
mbedAustin 11:cada08fc8a70 69 string (plus 1 for the NULL char). If there is already enough memory,
mbedAustin 11:cada08fc8a70 70 nothing happens, if not, the memory will be realloated to exactly this
mbedAustin 11:cada08fc8a70 71 amount.
mbedAustin 11:cada08fc8a70 72 */
mbedAustin 11:cada08fc8a70 73 void reserve( size_type n);
mbedAustin 11:cada08fc8a70 74
mbedAustin 11:cada08fc8a70 75 /** Resize string. If n is less than the current size, the string will be truncated.
mbedAustin 11:cada08fc8a70 76 If n is larger, the memory will be reallocated to exactly this amount, and
mbedAustin 11:cada08fc8a70 77 the additional characters will be NULL characters.
mbedAustin 11:cada08fc8a70 78 */
mbedAustin 11:cada08fc8a70 79 void resize( size_type n);
mbedAustin 11:cada08fc8a70 80
mbedAustin 11:cada08fc8a70 81 /** Resize string. If n is less than the current size, the string will be truncated.
mbedAustin 11:cada08fc8a70 82 If n is larger, the memory will be reallocated to exactly this amount, and
mbedAustin 11:cada08fc8a70 83 the additional characters will be c characters.
mbedAustin 11:cada08fc8a70 84 */
mbedAustin 11:cada08fc8a70 85 void resize( size_type n, char c);
mbedAustin 11:cada08fc8a70 86
mbedAustin 11:cada08fc8a70 87 /// swap contents
mbedAustin 11:cada08fc8a70 88 void swap( String& );
mbedAustin 11:cada08fc8a70 89
mbedAustin 11:cada08fc8a70 90 String substr(const size_type pos, size_type length) const;
mbedAustin 11:cada08fc8a70 91
mbedAustin 11:cada08fc8a70 92 // unchecked access:
mbedAustin 11:cada08fc8a70 93 char& operator[](const size_type i) { return p[i]; }
mbedAustin 11:cada08fc8a70 94 char operator[](const size_type i) const { return p[i]; }
mbedAustin 11:cada08fc8a70 95 // checked access:
mbedAustin 11:cada08fc8a70 96 char& at(const size_type i);
mbedAustin 11:cada08fc8a70 97 char at(const size_type i) const;
mbedAustin 11:cada08fc8a70 98
mbedAustin 11:cada08fc8a70 99 /// erase len characters at position pos
mbedAustin 11:cada08fc8a70 100 String& erase(size_type pos, size_type len);
mbedAustin 11:cada08fc8a70 101 /// Append n characters of a string
mbedAustin 11:cada08fc8a70 102 String& append(const char* str, size_type n);
mbedAustin 11:cada08fc8a70 103
mbedAustin 11:cada08fc8a70 104 int compare( size_type pos, size_type len, const String& str ) const;
mbedAustin 11:cada08fc8a70 105 int compare( size_type pos, size_type len, const char* str ) const;
mbedAustin 11:cada08fc8a70 106
mbedAustin 11:cada08fc8a70 107 int find_last_of(char c) const;
mbedAustin 11:cada08fc8a70 108
mbedAustin 11:cada08fc8a70 109 private:
mbedAustin 11:cada08fc8a70 110 // reallocate the internal memory
mbedAustin 11:cada08fc8a70 111 void new_realloc( size_type n);
mbedAustin 11:cada08fc8a70 112 char* strdup_never_null(const char* other);
mbedAustin 11:cada08fc8a70 113
mbedAustin 11:cada08fc8a70 114 char _return_value;
mbedAustin 11:cada08fc8a70 115
mbedAustin 11:cada08fc8a70 116 friend class ::Test_M2MString;
mbedAustin 11:cada08fc8a70 117
mbedAustin 11:cada08fc8a70 118 };
mbedAustin 11:cada08fc8a70 119 // class
mbedAustin 11:cada08fc8a70 120
mbedAustin 11:cada08fc8a70 121 bool
mbedAustin 11:cada08fc8a70 122 operator<(const String&, const String&);
mbedAustin 11:cada08fc8a70 123
mbedAustin 11:cada08fc8a70 124 } // namespace