Disk ARchive  2.4.5
 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 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00028 
00029 #ifndef TLV_HPP
00030 #define TLV_HPP
00031 
00032 #include "memory_file.hpp"
00033 #include "storage.hpp"
00034 
00035 namespace libdar
00036 {
00039 
00041 
00044     class tlv
00045     {
00046     public:
00047 
00048             // constructors & Co.
00049 
00050         tlv() { type = 0; value = NULL; };
00051         tlv(generic_file & f) { init(f); };
00052         tlv(const tlv & ref) { copy_from(ref); };
00053         ~tlv() { detruit(); };
00054 
00055         const tlv & operator = (const tlv & ref) { detruit(); copy_from(ref); return *this; };
00056 
00057             // methods (read / write tlv datastructure to file)
00058 
00059         void read(generic_file & f); //< same as the constructor but on an existing object
00060         void write(generic_file & f) const; //< dumps the tlv contents to file
00061 
00062             // methods to fill the tlv object
00063 
00064         U_16 get_type() const { return type; };      //< get the TLV type
00065         void set_type(U_16 val) { type = val; };     //< set the TLV type
00066         void set_contents(const memory_file & contents);  //< the generic_file object is provided to dump data to the tlv object
00067         void get_contents(memory_file & contents) const;  //< the generic_file object is provided to read data from the tlv object
00068 
00069 #ifdef LIBDAR_SPECIAL_ALLOC
00070         USE_SPECIAL_ALLOC(tlv);
00071 #endif
00072     private:
00073         U_16 type;
00074         storage *value;
00075 
00076         void init(generic_file & f);
00077         void copy_from(const tlv & ref);
00078         void detruit() { if(value != NULL) { delete value; value = NULL; } };
00079     };
00080 
00082 
00083 } // end of namespace
00084 
00085 #endif
00086 
00087 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines