00001 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #ifndef _CDRFILE_H_
00031 #define _CDRFILE_H_
00032 
00033 
00034 
00035 
00036 #include <cstdio>
00037 #include <string>
00038 
00039 
00040 
00041 
00042 #include "asn1fwd.h"
00043 
00044 
00045 namespace OSB_LIB {
00046     class Cdr;
00047     class Asn1Reader;
00048     class Asn1Writer;
00049 }
00050 
00051 
00052 
00053 namespace OSB_LIB {
00054 
00055 
00056 
00062     class FileBase {
00063     public:
00065         FileBase();
00067         virtual ~FileBase();
00068 
00069     private:
00071         FileBase(const FileBase&);
00073         FileBase& operator=(const FileBase&);
00074 
00075     public:                             
00077         bool isOpen() const;
00079         const std::string& name() const;
00081         const std::string& dir() const;
00087         const std::string path() const;
00094         bool eof();
00101         bool error();
00102 
00109         FILE* file();
00110 
00111     public:                             
00118         virtual int close();
00119 
00129         int remove();
00130 
00142         int rename(const std::string& newName);
00143 
00144     protected:
00155         int open(
00156             const std::string& dir,
00157             const std::string& name,
00158             const char*        mode
00159         );
00160 
00161     protected:
00163         FILE* file_;
00165         std::string name_;
00167         std::string dir_;
00168     };                                  
00169 
00173     class CdrInputFile : public FileBase {
00174     public:
00176         CdrInputFile();
00177 
00178     private:
00180         CdrInputFile(const CdrInputFile&);
00182         CdrInputFile& operator=(const CdrInputFile&);
00183 
00184     public:                             
00192         int open(
00193             const std::string& path,
00194                   bool         binary
00195         );
00204         int open(
00205             const std::string& dir,
00206             const std::string& name,
00207                   bool         binary
00208         );
00209 
00217         bool readLine(std::string* dest);
00218 
00225         bool readAsn1(Asn1Reader* dest);
00226     };                                  
00227 
00231     class CdrOutputFile : public FileBase {
00232     public:
00242         CdrOutputFile(
00243             const size_t        blockSize = 0,
00244             const unsigned char filler    = 0x00
00245         );
00246 
00257         virtual int close();
00258 
00259     private:
00261         CdrOutputFile(const CdrOutputFile&);
00263         CdrOutputFile& operator=(const CdrOutputFile&);
00264 
00265     public:
00275         int open(
00276             const std::string& path
00277         );
00278 
00289         int open(
00290             const std::string& dir,
00291             const std::string& name
00292         );
00293 
00300         int flush();
00301 
00311         int write(
00312             const Cdr&        cdr,
00313                   Asn1Writer& writer
00314         );
00315 
00324         int write(const std::string& record);
00325 
00334         int write(const Asn1Data& asn1);
00335 
00336     public:
00337         
00339 
00340         size_t blkSz_;
00342         unsigned char          filler_;
00344         size_t cnt_;
00346     };                                  
00347 }                                       
00348 #endif                                  // #ifndef _CDRFILE_H_