Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

data.hh

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique
00002 
00003 // This file is part of Qolyester.
00004 
00005 // Qolyester 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 // Qolyester 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 
00019 #ifndef QOLYESTER_UTL_DATA_HH
00020 # define QOLYESTER_UTL_DATA_HH 1
00021 
00022 # include <sys/types.h>
00023 # include <cassert>
00024 
00025 namespace olsr {
00026 
00027   namespace utl {
00028 
00029     // Forward declarations.
00030     struct Data;
00031     struct ConstData;
00032 
00033     namespace internal {
00034 
00035       // Constness related traits.
00037       template <class T, class U>
00038       struct convert {
00039         enum { valid = true };
00040       }; // End of struct convert.
00041 
00042       template <>
00043       struct convert<ConstData, Data> {
00044         enum { valid = false };
00045       }; // End of struct convert<Const, NonConst>.
00046 
00047       template <class C>
00048       struct other {
00049         typedef ConstData return_type;
00050       }; // End of struct other.
00051 
00052       template <>
00053       struct other<ConstData> {
00054         typedef Data return_type;
00055       }; // End of struct other<Const>.
00057 
00059       struct shared_data {
00060         shared_data(unsigned usecount, u_int8_t* buffer, ::size_t size);
00061 
00062         unsigned        usecount;
00063         u_int8_t*       buffer;
00064         ::size_t        size;
00065       }; // End of struct shared_data.
00066 
00067     } // End of namespace internal.
00068 
00070     template <class Self>
00071     struct Data_
00072     {
00074 
00075       Data_();
00076 
00077       explicit
00078       Data_(const ::size_t size);
00079 
00080       Data_(const Data_& other);
00081 
00082       template <class T>
00083       Data_(const Data_<T>& other);
00084 
00085       ~Data_();
00087 
00089       template <class T>
00090       Self&     operator = (const Data_<T>& other);
00091 
00092       Self&     operator=(const Data_<Self>& other);
00093 
00096       bool      empty() const;
00097 
00099       ::size_t  size() const;
00100 
00102       void      fit(unsigned len);
00103 
00105 
00106       Self      shrink_by(unsigned len) const;
00107       Self      shrink_to(unsigned len) const;
00109 
00111 
00112       Self      operator + (unsigned offset) const;
00113       Self&     operator += (unsigned offset);
00115 
00117       template <class T>
00118       ::size_t  operator - (const Data_<T>& rhs) const;
00119 
00121       const u_int8_t*   raw() const;
00122 
00124 
00125       void              dump(u_int8_t* p) const;
00126       void              dump(Data_<Data>& d) const;
00128 
00130 
00131       Self&             exact();
00132       const Self&       exact() const;
00134 
00135     protected:
00137       void              use();
00139       void              unuse();
00140 
00141       internal::shared_data*    data_;
00142       ::size_t                  instance_size_;
00143       unsigned                  offset_;
00144 
00145       friend
00146       class Data_<typename internal::other<Self>::return_type>;
00147     };
00148 
00149     struct Data : public Data_<Data>
00150     {
00151       Data();
00152       explicit Data(::size_t size);
00153 
00155       u_int8_t*         raw();
00156     }; // End of struct Data.
00157 
00158     struct ConstData : public Data_<ConstData>
00159     {
00160       ConstData();
00161       explicit ConstData(::size_t size);
00162       ConstData(const Data& d);
00163 
00164       ConstData&        operator = (const Data& d);
00165     }; // End of struct ConstData.
00166 
00167   } // namespace utl
00168 
00169 } // namespace olsr
00170 
00171 # ifndef QOLYESTER_DONTINCLUDE_HXX
00172 #  include "data.hxx"
00173 # endif
00174 
00175 #endif // ! QOLYESTER_UTL_DATA_HH

Generated on Thu Jul 28 21:21:46 2005 for Qolyester daemon by  doxygen 1.4.1