00001 // -*- c++ -*- 00002 // 00003 // $Id: bdbuffer.h 1200 2008-02-11 16:51:39Z rafi $ 00004 // 00005 // YAPET -- Yet Another Password Encryption Tool 00006 // Copyright (C) 2008 Rafael Ostertag 00007 // 00008 // This program is free software: you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation, either version 3 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 // 00021 00022 #ifndef _BDBUFFER_H 00023 #define _BDBUFFER_H 00024 00025 #ifdef HAVE_CONFIG_H 00026 #include <config.h> 00027 #endif 00028 00029 #ifdef HAVE_INTTYPES_H 00030 # include <inttypes.h> 00031 #endif 00032 00033 #ifdef HAVE_STDLIB_h 00034 # include <stdlib.h> 00035 #endif 00036 00037 #ifdef HAVE_STDEXCEPT 00038 # include <stdexcept> 00039 #endif 00040 00041 #include "yapetexception.h" 00042 00043 namespace YAPET { 00060 class BDBuffer { 00061 private: 00067 uint32_t _size; 00068 00074 uint8_t* data; 00075 00076 protected: 00078 uint8_t* alloc_mem(uint32_t s) throw(YAPETException); 00080 void free_mem(uint8_t* d, uint32_t s); 00081 00082 public: 00084 BDBuffer(uint32_t is) throw(YAPETException); 00085 BDBuffer(); 00086 BDBuffer(const BDBuffer& ed) throw(YAPETException); 00088 ~BDBuffer(); 00089 00091 void resize(uint32_t ns) throw(YAPETException); 00100 uint32_t size() const { return _size; } 00101 00103 uint8_t* at(uint32_t pos) throw(std::out_of_range); 00105 const uint8_t* at(uint32_t pos) const throw(std::out_of_range); 00106 00108 const uint8_t* operator()() const { return data; } 00110 uint8_t* operator()() { return data; } 00111 00113 operator uint8_t*() { return data; } 00115 operator const uint8_t*() const { return data; } 00116 00118 operator const void*() { return (void*)data; } 00119 00120 const BDBuffer& operator=(const BDBuffer& ed); 00121 00122 }; 00123 00124 } 00125 00126 #endif // _BDBUFFER_H 00127