• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _MTP_STRING_BUFFER_H
18 #define _MTP_STRING_BUFFER_H
19 
20 #include <log/log.h>
21 #include <stdint.h>
22 #include <string>
23 
24 // Max Character number of a MTP String
25 #define MTP_STRING_MAX_CHARACTER_NUMBER             255
26 
27 namespace android {
28 
29 class MtpDataPacket;
30 
31 // Represents a utf8 string, with a maximum of 255 characters
32 class MtpStringBuffer {
33 
34 private:
35     std::string     mString;
36 
37 public:
MtpStringBuffer()38                     MtpStringBuffer() {};
~MtpStringBuffer()39                     ~MtpStringBuffer() {};
40 
41     explicit        MtpStringBuffer(const char* src);
42     explicit        MtpStringBuffer(const uint16_t* src);
43                     MtpStringBuffer(const MtpStringBuffer& src);
44 
45     void            set(const char* src);
46     void            set(const uint16_t* src);
47 
48     inline void     append(const char* other);
49     inline void     append(MtpStringBuffer &other);
50 
51     bool            readFromPacket(MtpDataPacket* packet);
52     void            writeToPacket(MtpDataPacket* packet) const;
53 
isEmpty()54     inline bool     isEmpty() const { return mString.empty(); }
size()55     inline int      size() const { return mString.length(); }
56 
57     inline operator const char*() const { return mString.c_str(); }
58 };
59 
append(const char * other)60 inline void MtpStringBuffer::append(const char* other) {
61     mString += other;
62 }
63 
append(MtpStringBuffer & other)64 inline void MtpStringBuffer::append(MtpStringBuffer &other) {
65     mString += other.mString;
66 }
67 
68 }; // namespace android
69 
70 #endif // _MTP_STRING_BUFFER_H
71