Disk ARchive  2.4.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
tlv.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef TLV_HPP
00027 #define TLV_HPP
00028 
00029 #include "memory_file.hpp"
00030 #include "storage.hpp"
00031 
00032 namespace libdar
00033 {
00036 
00038 
00041     class tlv
00042     {
00043     public:
00044 
00045             // constructors & Co.
00046 
00047         tlv() { type = 0; value = NULL; };
00048         tlv(generic_file & f) { init(f); };
00049         tlv(const tlv & ref) { copy_from(ref); };
00050         ~tlv() { detruit(); };
00051 
00052         const tlv & operator = (const tlv & ref) { detruit(); copy_from(ref); return *this; };
00053 
00054             // methods (read / write tlv datastructure to file)
00055 
00056         void read(generic_file & f); //< same as the constructor but on an existing object
00057         void write(generic_file & f) const; //< dumps the tlv contents to file
00058 
00059             // methods to fill the tlv object
00060 
00061         U_16 get_type() const { return type; };      //< get the TLV type
00062         void set_type(U_16 val) { type = val; };     //< set the TLV type
00063         void set_contents(const memory_file & contents);  //< the generic_file object is provided to dump data to the tlv object
00064         void get_contents(memory_file & contents) const;  //< the generic_file object is provided to read data from the tlv object
00065 
00066 #ifdef LIBDAR_SPECIAL_ALLOC
00067         USE_SPECIAL_ALLOC(tlv);
00068 #endif
00069     private:
00070         U_16 type;
00071         storage *value;
00072 
00073         void init(generic_file & f);
00074         void copy_from(const tlv & ref);
00075         void detruit() { if(value != NULL) { delete value; value = NULL; } };
00076     };
00077 
00079 
00080 } // end of namespace
00081 
00082 #endif
00083 
00084 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines