MtpStringBuffer.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #ifndef _MTP_STRING_BUFFER_H
  17. #define _MTP_STRING_BUFFER_H
  18. #include <log/log.h>
  19. #include <stdint.h>
  20. #include <string>
  21. // Max Character number of a MTP String
  22. #define MTP_STRING_MAX_CHARACTER_NUMBER 255
  23. namespace android {
  24. class MtpDataPacket;
  25. // Represents a utf8 string, with a maximum of 255 characters
  26. class MtpStringBuffer {
  27. private:
  28. std::string mString;
  29. public:
  30. MtpStringBuffer() {};
  31. ~MtpStringBuffer() {};
  32. explicit MtpStringBuffer(const char* src);
  33. explicit MtpStringBuffer(const uint16_t* src);
  34. MtpStringBuffer(const MtpStringBuffer& src);
  35. void set(const char* src);
  36. void set(const uint16_t* src);
  37. inline void append(const char* other);
  38. inline void append(MtpStringBuffer &other);
  39. bool readFromPacket(MtpDataPacket* packet);
  40. void writeToPacket(MtpDataPacket* packet) const;
  41. inline bool isEmpty() const { return mString.empty(); }
  42. inline int size() const { return mString.length(); }
  43. inline operator const char*() const { return mString.c_str(); }
  44. };
  45. inline void MtpStringBuffer::append(const char* other) {
  46. mString += other;
  47. }
  48. inline void MtpStringBuffer::append(MtpStringBuffer &other) {
  49. mString += other.mString;
  50. }
  51. }; // namespace android
  52. #endif // _MTP_STRING_BUFFER_H