asn1writer.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.1 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _ASN1WRITER_H_
00031 #define _ASN1WRITER_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <list>
00037 
00038 // + libraries
00039 
00040 // + local headers
00041 #include "asn1.h"
00042 
00043 // + class declarations
00044 namespace OSB_LIB {
00045     class Asn1Encoder;                  // asn1encode.h
00046     class Asn1DataEncoder;              // asn1encode.h
00047 }
00048 
00049 // ************************************************************************
00050 // namespace extensions
00051 namespace OSB_LIB {
00052 
00053 // ************************************************************************
00054 // forward declarations
00055     class Asn1Buffer;
00056 
00057 // ************************************************************************
00058 // type definitions
00059 
00060 // ************************************************************************
00061 // class definitions
00065     class Asn1BufferCache {
00075         typedef std::list<Asn1Buffer*> Buffers;
00076 
00078         friend class Asn1Buffer;
00079 
00080     public:
00082         Asn1BufferCache();
00084         ~Asn1BufferCache();
00085 
00086     private:
00088         Asn1BufferCache(const Asn1BufferCache&);
00090         Asn1BufferCache& operator=(const Asn1BufferCache&);
00091 
00092     private:
00103         Asn1Buffer* get();
00109         void put(Asn1Buffer* buf);
00110 
00111     private:
00113         bool indtor_;
00115         Buffers pool_;
00116     };                                  // class Asn1BufferCache
00117 
00121     class Asn1Buffer {
00127         friend class Asn1Writer;
00129         friend class Asn1BufferCache;
00131         typedef std::list<Asn1Buffer*> Members;
00132     public:
00134         Asn1Buffer(Asn1BufferCache& cache);
00136         void destroy();
00137     private:
00139         ~Asn1Buffer();
00140     private:
00142         Asn1Buffer(const Asn1Buffer&);
00144         Asn1Buffer& operator=(const Asn1Buffer&);
00145     public:
00155         void add(
00156             const Asn1Encoder& encoder,
00157                   bool         force = false
00158         );
00159 
00169         void add(
00170             const Asn1DataEncoder& encoder,
00171                   bool             force = false
00172         );
00173 
00179         bool write(FILE* out) const;
00180 
00189         void clearData();
00190     private:
00192         size_t memberSize() const;
00193 
00204         bool getData(
00205             const Asn1Encoder& encoder,
00206                   bool         force
00207         );
00208 
00220         bool getData(
00221             const Asn1DataEncoder& encoder,
00222                   bool             force
00223         );
00224 
00225     private:
00232         size_t totSize_;
00234         Asn1Data data_;
00236         Members members_;
00237 
00239         Asn1Tag tag_;
00241         Asn1Len dataLen_;
00242 
00244         Asn1Data tagBuf_;
00246         Asn1BufferCache& cache_;
00247     };                                  // class Asn1Buffer
00248 
00252     class Asn1Writer {
00253     public:
00255         Asn1Writer();
00256     private:
00258         Asn1Writer(const Asn1Writer&);
00260         Asn1Writer& operator=(const Asn1Writer&);
00261     public:
00263         void clear();
00269         void encode(
00270             const Asn1Encoder& encoder
00271         );
00279         void encode(
00280             const Asn1DataEncoder& encoder
00281         );
00282 
00288         bool write(FILE* out) const;
00289 
00290     private:
00292         Asn1BufferCache cache_;
00294         Asn1Buffer result_;
00295     };                                  // class Asn1Writer
00296 }                                       // namespace OSB_LIB
00297 
00298 // ************************************************************************
00299 // inline definitions
00300 namespace OSB_LIB {
00301 }                                       // namespace OSB_LIB
00302 #endif                                  // #ifndef _ASN1WRITER_H_

Generated on Sat Sep 2 14:06:31 2006 for OSB Library by  doxygen 1.4.7