1/* 2 * Copyright (C) 2014 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 __DMBUFFER_H__ 18#define __DMBUFFER_H__ 19 20#ifndef __cplusplus 21#error "This is a C++ header file; it requires C++ to compile." 22#endif 23 24#include "xpl_Types.h" 25#include "dmstring.h" 26 27/** 28 * A simple Buffer class. 29 */ 30class DMBuffer 31{ 32 public: 33 DMBuffer(); 34 ~DMBuffer(); 35 36 DMBuffer & operator=(const DMBuffer& pBuffer); 37 38 inline UINT8* getBuffer() const {return m_pBuf;} 39 40 inline UINT32 getSize() const {return m_nSize;} 41 42 UINT8 * allocate(UINT32 nCapacity); 43 44 UINT8 * assign(CPCHAR szStr); 45 46 UINT8 * assign(const UINT8 * pBuffer, INT32 size); 47 void append(const UINT8 * pBuffer, INT32 size); 48 49 inline UINT8 * assign(CPCHAR szStr, INT32 size) { return assign((UINT8*)szStr,size); } 50 51 void clear(); 52 void free(); 53 void reset(); 54 55 void setSize(UINT32 size); 56 57 void copyTo(UINT8 **ppBuffer) const; 58 59 void copyTo(INT32 offset,INT32 size, DMBuffer& pBuffer) const; 60 61 inline void copyTo(char ** ppStr) const { copyTo((UINT8**)ppStr); } 62 63 void copyTo(char * pStr) const; 64 65 void copyTo(DMString & sStr) const; 66 67 BOOLEAN compare(CPCHAR pStr) const; 68 69 BOOLEAN compare(CPCHAR pStr, UINT32 len) const; 70 71 BOOLEAN empty() { return ((m_nSize == 0) ? TRUE : FALSE); } 72 73 void attach(UINT8 * pBuffer, INT32 nCapacity); 74 75 UINT8 * detach(); 76 77 78 private: 79 UINT8 *m_pBuf; 80 UINT32 m_nSize; 81 UINT32 m_nCapacity; 82}; 83 84#endif //End of include File 85