asn1tagdes.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 _ASN1TAGDES_H_
00031 #define _ASN1TAGDES_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <iosfwd>
00037 #include <list>
00038 #include <set>
00039 #include <string>
00040 
00041 // + libraries
00042 
00043 // + local headers
00044 #include "asn1.h"
00045 #include "osberror.h"
00046 
00047 // + class declarations
00048 namespace OSB_LIB {
00049     class Asn1Info;
00050 }
00051 
00052 // ************************************************************************
00053 // namespace extensions
00054 namespace OSB_LIB {
00055 
00056 // ************************************************************************
00057 // forward declarations
00058 
00059 // ************************************************************************
00060 // type definitions
00061 
00062 // ************************************************************************
00063 // class definitions
00072     class Asn1TagDes {
00073     public:
00075         typedef std::list<Asn1TagDes> SubTypes;
00076     public:
00086         typedef void (*Decoder)(
00087             const Asn1Byte*    data,
00088             const size_t       size,
00089                   std::string& dest
00090         );
00091 
00092     public:
00094         explicit Asn1TagDes(const Asn1Tag& tag = Asn1Tag());
00095 
00096     public:
00098         Asn1Tag tag_;
00100         std::string des_;
00101 
00102     public:
00108         void buildFrom(
00109             Asn1Info& asn1
00110         );
00116         const SubTypes& subTypes() const;
00126         void print(
00127                   std::ostream& os,
00128             const std::string&  indent = ""
00129         ) const;
00130 
00131     public:                             // primitive types
00133         const std::string decoderName() const;
00134 
00136         void setDecoderName(
00137             const std::string& decoderName
00138         );
00139 
00150         bool setDecoders(std::set<std::string>& errors);
00151 
00161         Decoder decoder() const;
00162 
00163     public:                             // constructed types
00165         void add(const Asn1TagDes& subDes);
00167         void add(const SubTypes& subTypes);
00169         void moveOut(
00170             SubTypes& dest,
00171             int       level
00172         );
00173 
00182         static Asn1TagDes* find(
00183                   SubTypes& src,
00184             const Asn1Tag&  tag
00185         );
00186     private:                            // primitive types
00188         std::string decoderName_;
00190         mutable Decoder decoder_;
00191     private:                            // constructed types
00193         SubTypes subTypes_;
00194     };                                  // class Asn1TagDes
00195 
00199     class Asn1InputInfo {
00200     public:
00202         typedef std::list<Asn1TagDes> Asn1DesList;
00204         typedef std::list<Asn1Tag>::const_iterator TagIter;
00205 
00206     public:
00214         Asn1InputInfo();
00215     public:
00217         void clearDes();
00218 
00228         bool read(
00229             const std::string& path,
00230                   OsbErrors&   errors
00231         );
00232 
00243         bool setDecoders(
00244             OsbErrors& errors
00245         );
00246 
00259         void write(
00260             const std::string& path,
00261                   int          flatten = -1
00262         ) const;
00263 
00265         void add(const Asn1TagDes& asn1Des);
00266 
00277         const Asn1TagDes* find(
00278             TagIter begin,
00279             TagIter end
00280         ) const;
00281 
00283         const Asn1DesList& asn1Des() const;
00284 
00295         void print(
00296             std::ostream& os,
00297             int           flatten = -1
00298         ) const;
00299 
00300     private:
00309         static Asn1TagDes* find(
00310                   Asn1DesList& src,
00311             const Asn1Tag&     tag
00312         );
00313 
00322         static const Asn1TagDes* find(
00323             const Asn1DesList& src,
00324             const Asn1Tag&     tag
00325         );
00326 
00338         static const Asn1TagDes* find(
00339             const Asn1DesList& src,
00340                   TagIter      begin,
00341                   TagIter      end
00342         );
00343 
00344     public:
00350         size_t blkSize_;
00352         Asn1Byte blkFiller_;
00353     private:
00355         Asn1DesList asn1Des_;
00356     };                                  // class Asn1InputInfo
00357 
00365     class Asn1DesParser {
00366     public:
00367         // defined below
00368         class Error;
00369     public:
00376         explicit Asn1DesParser(
00377             std::istream& is,
00378             size_t        lineNo = 1
00379         );
00380 
00381     public:
00390         bool getDes(Asn1TagDes& dest);
00392         size_t lineNo() const;
00394         size_t colNo() const;
00395     private:
00397         Asn1DesParser(const Asn1DesParser& rhs);
00399         Asn1DesParser operator=(const Asn1DesParser& rhs);
00400     private:
00410         bool getDes(
00411             Asn1TagDes& dest,
00412             bool        readTag
00413         );
00415         bool getChar(char& c);
00417         bool nextToken();
00419         void getComposed(Asn1TagDes& parent);
00421         void getPrimitive(Asn1TagDes& dest);
00423         Error error(OsbBaseError::ErrorNo errNo);
00424 
00425     private:
00427         std::istream& is_;
00429         size_t lineNo_;
00431         size_t colNo_;
00433         std::string curToken_;
00435         char separator_;
00436     };                                  // class Asn1DesParser
00437 
00441     class Asn1DesParser::Error : public OsbException {
00442     public:
00444         Error(
00445             ErrorNo      errNo,
00446             size_t       line,
00447             size_t       col
00448         );
00449     public:
00451         size_t line() const;
00453         size_t col() const;
00454     private:
00456         size_t line_;
00458         size_t col_;
00459     };                                  // class Asn1DesParser::Error
00460 }                                       // namespace OSB_LIB
00461 
00462 // ************************************************************************
00463 // inline definitions
00464 namespace OSB_LIB {
00465 }                                       // namespace OSB_LIB
00466 #endif                                  // #ifndef _ASN1TAGDES_H_

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