1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef WBXML_STL_H 19 #define WBXML_STL_H 20 21 #ifdef PLATFORM_ANDROID 22 23 #include <utils/String8.h> 24 #include <utils/Vector.h> 25 using android::String8; 26 using android::Vector; 27 28 class string: public String8 29 { 30 public: string()31 string() {} string(const string & o)32 string(const string& o) : 33 String8(o) 34 { 35 } string(const char * o)36 string(const char* o) : 37 String8(o) 38 { 39 } string(const char * o,size_t len)40 string(const char* o, size_t len) : 41 String8(o, len) 42 { 43 } 44 string & operator=(const char* other) 45 { 46 setTo(other); 47 return *this; 48 } assign(const char * other,int len)49 string & assign(const char* other, int len) 50 { 51 setTo(other, len); 52 return *this; 53 } empty(void)54 bool empty(void) const 55 { 56 return size() == 0; 57 } c_str(void)58 const char *c_str(void) const 59 { 60 return String8::string(); 61 } 62 string & operator+=(const string & o) 63 { 64 append(o); 65 return *this; 66 } 67 string & operator+=(const char * other) 68 { 69 append(other); 70 return *this; 71 } 72 string & operator+=(char ch) 73 { 74 char c[2] = {ch, 0}; // temporary workaround for String8.append(str, len) bug 75 append(c, 1); 76 return *this; 77 } clear(void)78 void clear(void) 79 { 80 setTo(""); 81 } 82 }; 83 84 template <class T> 85 class vector: public Vector<T> 86 { 87 public: back(void)88 T & back(void) 89 { 90 return Vector<T>::editTop(); 91 } back(void)92 const T & back(void) const 93 { 94 return Vector<T>::top(); 95 } push_back(const T & val)96 void push_back(const T& val) 97 { 98 Vector<T>::push(val); 99 } pop_back(void)100 void pop_back(void) 101 { 102 Vector<T>::pop(); 103 } empty(void)104 bool empty(void) const 105 { 106 return Vector<T>::isEmpty(); 107 } 108 }; 109 110 #else 111 112 #include <string> 113 #include <vector> 114 using std::string; 115 using std::vector; 116 117 #endif 118 119 #endif 120 121