Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

exaltcodec.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002     exaltcodec.cpp  -  Definition of ExaltCodec class methods
00003                              -------------------
00004     begin                : June 21 2002
00005     copyright            : (C) 2003 by Vojtìch Toman
00006     email                : vtoman@lit.cz
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00026 #ifdef __GNUG__
00027 # pragma implementation
00028 #endif
00029 
00030 
00031 #include "exaltcodec.h"
00032 
00033 
00037 #define SHOW_RUNNING_TIME(_t1_, _t2_)                                                           \
00038 {                                                                                               \
00039   OUTPUTENL("  Running time: \t\t\t" << (double)(_t2_ - _t1_) / CLOCKS_PER_SEC << " s");        \
00040   OUTPUTEENDLINE;                                                                               \
00041 }
00042 
00043 
00044 
00048 ExaltCodec::ExaltCodec(void)
00049   : XmlCodecBase()
00050 {
00051   NEW(xmlCodec, XmlCodec());
00052 }
00053 
00054 
00055 
00059 ExaltCodec::~ExaltCodec(void)
00060 {
00061   if (xmlCodec)
00062     DELETE(xmlCodec);
00063 
00064   deleteDefaultTextCodec();
00065 }
00071 void ExaltCodec::initializePushCoder(IODevice *outDevice)
00072 {
00073   xmlCodec->initializePushCoder(outDevice);
00074 }
00075 
00076 
00077 
00083 void ExaltCodec::initializePushCoder(const char *outFileName)
00084 {
00085   FileDevice *outFileDevice;
00086 
00087   NEW(outFileDevice, FileDevice);
00088   outFileDevice->prepare(outFileName, ios::out);
00089 
00090   xmlCodec->initializePushCoder(outFileDevice);
00091 }
00092 
00093 
00094 
00102 bool ExaltCodec::encodePush(const char *data, int length, bool isFinal = false)
00103 {
00104   return xmlCodec->encodePush(data, length, isFinal);
00105 }
00106 
00107 
00108 
00109 
00110 
00117 bool ExaltCodec::encode(IODevice *inDevice, IODevice *outDevice)
00118 {
00119   bool res;
00120 
00121   clock_t t1, t2;
00122 
00123   t1 = clock();
00124 
00125   if (!textCodec)
00126     //use default TextCodec if none has been specified
00127     createDefaultTextCodec();
00128 
00129     {
00130       if (textCodec)
00131         xmlCodec->setTextCodec(textCodec);
00132 
00133       res = xmlCodec->encode(inDevice, outDevice);
00134     }
00135 
00136   t2 = clock();
00137   if (ExaltOptions::getOption(ExaltOptions::Verbose) == ExaltOptions::Yes)
00138     {
00139       SHOW_RUNNING_TIME(t1, t2);
00140     }
00141 
00142   return res;
00143 }
00144 
00145 
00146 
00153 bool ExaltCodec::encode(const char *inFileName, const char *outFileName)
00154 {
00155   FileDevice *inFileDevice, *outFileDevice;
00156 
00157   NEW(inFileDevice, FileDevice);
00158   inFileDevice->prepare(inFileName, ios::in);
00159 
00160   NEW(outFileDevice, FileDevice);
00161   outFileDevice->prepare(outFileName, ios::out);
00162 
00163   bool res = encode(inFileDevice, outFileDevice);
00164 
00165   inFileDevice->finish();
00166   outFileDevice->finish();
00167 
00168   DELETE(inFileDevice);
00169   DELETE(outFileDevice);
00170 
00171   return res;
00172 }
00173 
00174 
00175 
00182 bool ExaltCodec::decode(IODevice *inDevice, IODevice *outDevice)
00183 {
00184   OutputSAXReceptor *receptor;
00185   bool res;
00186 
00187   clock_t t1, t2;
00188 
00189 
00190   t1 = clock();
00191 
00192   if (!textCodec)
00193     //create default text codec if none has been specified
00194     createDefaultTextCodec();
00195 
00196   //we create default SAX receptor which outputs to the outDevice
00197   NEW(receptor, OutputSAXReceptor(outDevice));
00198 
00199 
00200     {
00201       if (textCodec)
00202         xmlCodec->setTextCodec(textCodec);
00203 
00204       res = xmlCodec->decode(inDevice, receptor);
00205 
00206     }
00207 
00208   t2 = clock();
00209 
00210   if (ExaltOptions::getOption(ExaltOptions::Verbose) == ExaltOptions::Yes)
00211     {
00212       SHOW_RUNNING_TIME(t1, t2);
00213     }
00214 
00215   DELETE(receptor);
00216 
00217   return res;
00218 }
00219 
00220 
00221 
00228 bool ExaltCodec::decode(const char *inFileName, const char *outFileName)
00229 {
00230   FileDevice *inFileDevice, *outFileDevice;
00231 
00232   NEW(inFileDevice, FileDevice);
00233   inFileDevice->prepare(inFileName, ios::in);
00234 
00235   NEW(outFileDevice, FileDevice);
00236   outFileDevice->prepare(outFileName, ios::out);
00237 
00238   bool res = decode(inFileDevice, outFileDevice);
00239 
00240   outFileDevice->finish();
00241 
00242   DELETE(inFileDevice);
00243   DELETE(outFileDevice);
00244 
00245   return res;
00246 }
00247 
00248 
00249 
00257 bool ExaltCodec::decode(IODevice *inDevice, SAXReceptor *receptor, void *userData = 0)
00258 {
00259   XmlCodec *xmlCodec;
00260   bool res;
00261 
00262   NEW(xmlCodec, XmlCodec);
00263 
00264   res = xmlCodec->decode(inDevice, receptor, userData);
00265 
00266   DELETE(xmlCodec);
00267 
00268   return res;
00269 }
00270 
00271 
00272 
00280 bool ExaltCodec::decode(const char *inFileName, SAXReceptor *receptor, void *userData = 0)
00281 {
00282   FileDevice *inFileDevice;
00283 
00284   NEW(inFileDevice, FileDevice);
00285 
00286   try
00287     {
00288       inFileDevice->prepare(inFileName, ios::in);
00289     }
00290   catch (ExaltException)
00291     {
00292       FATAL("Unable to set \"" << inFileName <<"\" as input device!");
00293     }
00294 
00295   bool res = decode(inFileDevice, receptor, userData);
00296 
00297   DELETE(inFileDevice);
00298 
00299   return res;
00300 }

Generated on Wed Feb 5 10:43:01 2003 for Exalt by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002