edits
[iotcloud.git] / version2 / src / C / IoTString.h
1 #ifndef IOTSTRING_H
2 #define IOTSTRING_H
3
4 #include "array.h"
5
6 /**
7  * IoTString wraps the underlying char string.
8  * @author Brian Demsky <bdemsky@uci.edu>
9  * @version 1.0
10  */
11
12 class IoTString {
13 private:
14         Array<char> *array;
15         IoTString() {}
16
17         /**
18          * Builds an IoTString object around the char array.  This
19          * constructor makes a copy, so the caller is free to modify the char array.
20          */
21
22 public:
23         IoTString(Array<char> *_array) : array(new Array<char>(_array)) {}
24         ~IoTString() {}
25
26         /**
27          * Internal method to grab a reference to our char array.  Caller
28          * must not modify it.
29          */
30
31         Array<char> *internalBytes() { return array; }
32
33         /**
34          * Returns a copy of the underlying char string.
35          */
36
37         Array<char> *getBytes() { return new Array<char>(array); }
38
39         /**
40          * Returns the length in chars of the IoTString.
41          */
42
43         bool equals(IoTString *str) {
44                 uint strlength = str->array->length();
45                 uint thislength = array->length();
46                 if (strlength != thislength)
47                         return false;
48
49                 int result = memcmp(str->array->internalArray(), array->internalArray(), strlength);
50                 return result == 0;
51         }
52
53         int length() { return array->length(); }
54         friend IoTString *IoTString_shallow(Array<char> *_array);
55 };
56
57 IoTString *IoTString_shallow(Array<char> *_array) {
58         IoTString *str = new IoTString();
59         str->array = _array;
60         return str;
61 }
62 #endif