SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
String.hpp
1 //
2 // String.hpp
3 //
4 // Sketchup C++ Wrapper for C API
5 // MIT License
6 //
7 // Copyright (c) 2017 Tom Kaneko
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
18 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 // SOFTWARE.
26 //
27 
28 #ifndef String_hpp
29 #define String_hpp
30 
31 #include <stdio.h>
32 #include <string>
33 
34 #include <SketchUpAPI/unicodestring.h>
35 namespace CW {
36 
37 /*
38 * StringRef wrapper
39 */
40 enum class StringEncoding {
41  UTF8,
42  UTF16
43 };
44 
45 class String {
46  private:
47  SUStringRef m_string;
48  StringEncoding m_encoding;
49 
50  // Disallow copying for simplicity
51  //String(const String& copy);
52  //String& operator= (const String& copy);
53 
54  static SUStringRef create_string_ref();
55  static SUStringRef create_string_ref(const std::string string_input, StringEncoding enc = StringEncoding::UTF8);
56  static SUStringRef create_string_ref(const char string_input[]);
57  static SUStringRef create_string_ref(const unichar string_input[]);
58 
59  public:
60  String();
61  String(SUStringRef string_ref);
62  String(const std::string &string_input, StringEncoding enc = StringEncoding::UTF8);
63  String(const char string_input[]);
64  String(const unichar string_input[]);
65 
66  /** Copy Constructor */
67  String(const String& other);
68 
69  /** Copy Assignment operator */
70  String& operator=(String& other);
71 
72 
73  ~String();
74 
75  operator SUStringRef&() {return m_string;}
76  operator SUStringRef*() {return &m_string;}
77  operator SUStringRef() const {return m_string;}
78 
79  /**
80  * Compares two strings for equality.
81  */
82  friend bool operator==(const String &lhs, const String &rhs);
83 
84  /*
85  * Convert to std::string
86  */
87  std::string std_string() const;
88  operator std::string() const;
89 
90 // char& operator [](size_t i);
91 
92  /*
93  * Return the SUStringRef object.
94  */
95  SUStringRef ref() const;
96 
97  /*
98  * Return the length of the string, in bytes. Including the null terminator at the end.
99  */
100  size_t size() const;
101 
102  /**
103  * Return whether this string is empty or not.
104  */
105  bool empty() const;
106 
107 };
108 
109 } /* namespace CW */
110 
111 
112 #endif /* String_hpp */
Definition: Color.hpp:34