Misc.h
Go to the documentation of this file.00001 #ifndef MISC_H
00002 #define MISC_H
00003
00004
00005
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 #include <iostream>
00031 #include <iterator>
00032 #include <fstream>
00033 #include <string>
00034 #include <vector>
00035 #include <set>
00036 #include <map>
00037
00038 #include <boost/filesystem/path.hpp>
00039 #include <boost/filesystem/convenience.hpp>
00040 #include <boost/algorithm/string/trim.hpp>
00041 #include <boost/algorithm/string/predicate.hpp>
00042 #include <boost/algorithm/string/split.hpp>
00043
00044 typedef unsigned char xmlChar;
00045
00046 struct _xmlNode;
00047 typedef struct _xmlNode xmlNode;
00048 typedef xmlNode *xmlNodePtr;
00049
00050 struct _xmlDoc;
00051 typedef struct _xmlDoc xmlDoc;
00052 typedef xmlDoc *xmlDocPtr;
00053
00054 struct _xsltStylesheet;
00055 typedef struct _xsltStylesheet xsltStylesheet;
00056 typedef xsltStylesheet *xsltStylesheetPtr;
00057
00058 extern "C" int xmlLoadExtDtdDefaultValue;
00059
00060 namespace asdm {
00075 bool directoryExists(const char* dir);
00076
00085 bool createDirectory(const char* dir);
00086
00094 bool createPath(const char* path);
00095
00096
00100 #define ByteSwap5(x) ByteSwap((unsigned char *) &x,sizeof(x))
00101 void ByteSwap(unsigned char * b, int n);
00102
00107 class ByteOrder {
00108 public:
00109 static const ByteOrder* Little_Endian;
00110 static const ByteOrder* Big_Endian;
00111 static const ByteOrder* Machine_Endianity;
00112
00121 std::string toString() const ;
00122
00130 static const ByteOrder* fromString(const std::string & s);
00131
00132 private:
00133 std::string name_;
00134 int endianity_;
00135
00136 ByteOrder(const std::string & name, int endianity);
00137 virtual ~ByteOrder();
00138 static const ByteOrder* machineEndianity();
00139 };
00140
00148 std::string uniqSlashes(const std::string& s);
00149
00150 class ASDMUtilsException {
00151 public:
00152 ASDMUtilsException();
00153 ASDMUtilsException(const std::string& message);
00154
00155 const std::string& getMessage();
00156
00157 private:
00158 std::string message;
00159 };
00160
00161 class ASDMUtils {
00162 public :
00163 enum Origin { UNKNOWN, ALMA, EVLA };
00164 static std::string version (const std::string& asdmPath);
00165 static std::vector<std::string> telescopeNames(const std::string& asdmPath);
00166 static Origin origin(const std::vector<std::string>& telescopeNames);
00167 static std::vector<std::string> xmlFilenames(const std::string& asdmPath);
00168
00169 static std::string pathToV2V3ALMAxslTransform() ;
00170 static std::string pathToV2V3EVLAxslTransform() ;
00171 static std::string nameOfV2V3xslTransform(ASDMUtils::Origin origin);
00172
00173 struct DotXMLFilter {
00174 public:
00175 DotXMLFilter(std::vector<std::string>& filenames);
00176
00177 void operator() ( boost::filesystem::directory_entry& p);
00178 private:
00179 std::vector<std::string>* filenames;
00180 };
00181
00182 private :
00183 static bool initialize();
00184 static bool initialized;
00185 static bool hasChild(xmlDocPtr, xmlNodePtr node, const xmlChar* childName);
00186 static std::string parseRow(xmlDocPtr, xmlNodePtr node, const xmlChar* childName);
00187 static std::set<std::string> evlaValidNames;
00188 static std::set<std::string> almaValidNames;
00189 static std::map<ASDMUtils::Origin, std::string> filenameOfV2V3xslTransform;
00190 static std::map<std::string, std::string> rootSubdir ;
00191
00192 static std::string pathToxslTransform( const std::string& xsltFilename);
00193 };
00194
00195
00221 class ASDMParseOptions {
00222 friend class ASDM;
00223
00224 public:
00236 ASDMParseOptions();
00237
00241 ASDMParseOptions(const ASDMParseOptions& x);
00242
00247 virtual ~ASDMParseOptions();
00248
00252 ASDMParseOptions & operator=(const ASDMParseOptions & rhs);
00253
00254
00258 ASDMParseOptions& asALMA();
00259
00263 ASDMParseOptions& asIRAM_PDB();
00264
00268 ASDMParseOptions& asEVLA();
00269
00273 ASDMParseOptions& asV2();
00274
00278 ASDMParseOptions& asV3();
00279
00286 ASDMParseOptions& loadTablesOnDemand(bool b);
00287
00294 ASDMParseOptions& checkRowUniqueness(bool b);
00295
00299 friend std::ostream& operator<<(std::ostream& output, const ASDMParseOptions& p);
00300
00301 std::string toString() const;
00302
00303 private:
00304 ASDMUtils::Origin origin_;
00305 bool detectOrigin_;
00306 std::string version_;
00307 bool detectVersion_;
00308 bool loadTablesOnDemand_;
00309 bool checkRowUniqueness_;
00310 };
00311
00316 class XSLTransformerException {
00317
00318 public:
00322 XSLTransformerException();
00323
00328 XSLTransformerException(const std::string & m);
00329
00333 virtual ~XSLTransformerException();
00334
00339 std::string getMessage() const;
00340
00341 protected:
00342 std::string message;
00343
00344 };
00345
00346 inline XSLTransformerException::XSLTransformerException() : message ("XSLTransformerException") {}
00347 inline XSLTransformerException::XSLTransformerException(const std::string& m) : message(m) {}
00348 inline XSLTransformerException::~XSLTransformerException() {}
00349 inline std::string XSLTransformerException::getMessage() const {
00350 return "XSLTransformerException : " + message;
00351 }
00352
00362 class XSLTransformer {
00363 public:
00369 XSLTransformer();
00370
00374 virtual ~XSLTransformer();
00375
00385 XSLTransformer(const std::string& xsltPath);
00386
00397 void setTransformation(const std::string& xsltPath);
00398
00412 std::string operator()(const std::string& xmlPath);
00413
00414 private:
00415
00416 xsltStylesheetPtr cur;
00417
00418 XSLTransformer& operator=(const XSLTransformer & rhs);
00419 XSLTransformer(const XSLTransformer & rsh);
00420 };
00421
00422
00432 class CharComparator {
00433 public:
00434 CharComparator(std::ifstream * is_p = NULL, off_t limit = 0);
00435 bool operator() (char cl, char cr);
00436
00437 private:
00438 std::ifstream* is_p;
00439 off_t limit;
00440 char* asdmDebug_p;
00441 };
00442
00455 class CharCompAccumulator {
00456 private:
00457 std::string* accumulator_p;
00458 std::ifstream* is_p;
00459 off_t limit;
00460 int nEqualChars;
00461 char* asdmDebug_p;
00462 public:
00470 CharCompAccumulator(std::string* accumulator_p = NULL, std::ifstream * is_p = NULL , off_t limit = 0);
00471
00478 bool operator()(char cl, char cr);
00479 };
00480 }
00481 #endif // MISC_H
00482