E57 Foundation API v1.1.312  Aug. 10, 2011
C:/Projects32/e57-3d-imgfmt/trunk/include/E57Foundation.h
Go to the documentation of this file.
00001 /*
00002  * E57Foundation.h - public header of E57 Foundation API for reading/writing .e57 files.
00003  *
00004  * Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
00005  *
00006  * Permission is hereby granted, free of charge, to any person or organization
00007  * obtaining a copy of the software and accompanying documentation covered by
00008  * this license (the "Software") to use, reproduce, display, distribute,
00009  * execute, and transmit the Software, and to prepare derivative works of the
00010  * Software, and to permit third-parties to whom the Software is furnished to
00011  * do so, all subject to the following:
00012  *
00013  * The copyright notices in the Software and this entire statement, including
00014  * the above license grant, this restriction and the following disclaimer,
00015  * must be included in all copies of the Software, in whole or in part, and
00016  * all derivative works of the Software, unless such copies or derivative
00017  * works are solely in the form of machine-executable object code generated by
00018  * a source language processor.
00019  *
00020  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00023  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00024  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00025  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00026  * DEALINGS IN THE SOFTWARE.
00027  */
00028 #ifndef E57FOUNDATION_H_INCLUDED
00029 #define E57FOUNDATION_H_INCLUDED
00030 
00032 
00033 // Define the following symbol to enable heap corruption and memory leakage debugging:
00034 //#define E57_DEBUG_MEMORY 1
00035 #if E57_DEBUG_MEMORY
00036 #  define _CRTDBG_MAP_ALLOC
00037 #  include <stdlib.h>
00038 #  include <crtdbg.h>
00039 #endif
00040 
00041 #include <vector>
00042 #include <string>
00043 #include <iostream>
00044 #include <float.h>
00045 #include <boost/shared_ptr.hpp>
00046 #include <boost/weak_ptr.hpp>
00047 #include <boost/enable_shared_from_this.hpp>
00048 #include <boost/cstdint.hpp>    // for int8_t, int16_t, int32_t, etc...
00049 
00050 
00051 #ifndef DOXYGEN  // Doxygen is not handling namespaces well in @includelineno commands, so disable
00052 namespace e57 {
00053 #endif
00054 
00055 // Use Boost type names for signed/unsigned integers in various witdths
00056 using boost::int8_t;
00057 using boost::uint8_t;
00058 using boost::int16_t;
00059 using boost::uint16_t;
00060 using boost::int32_t;
00061 using boost::uint32_t;
00062 using boost::int64_t;
00063 using boost::uint64_t;
00064 
00065 // Shorthand for unicode string
00067 typedef std::string ustring;
00068 
00070 enum NodeType {
00071     E57_STRUCTURE         = 1,  
00072     E57_VECTOR            = 2,  
00073     E57_COMPRESSED_VECTOR = 3,  
00074     E57_INTEGER           = 4,  
00075     E57_SCALED_INTEGER    = 5,  
00076     E57_FLOAT             = 6,  
00077     E57_STRING            = 7,  
00078     E57_BLOB              = 8   
00079 };
00080 
00082 enum FloatPrecision {
00083     E57_SINGLE = 1,  
00084     E57_DOUBLE = 2   
00085 };
00086 
00088 enum MemoryRepresentation {
00089     E57_INT8     = 1,  
00090     E57_UINT8    = 2,  
00091     E57_INT16    = 3,  
00092     E57_UINT16   = 4,  
00093     E57_INT32    = 5,  
00094     E57_UINT32   = 6,  
00095     E57_INT64    = 7,  
00096     E57_BOOL     = 8,  
00097     E57_REAL32   = 9,  
00098     E57_REAL64   = 10, 
00099     E57_USTRING  = 11  
00100 };
00101 
00103 const int E57_FOUNDATION_API_MAJOR = 0;
00104 
00106 const int E57_FOUNDATION_API_MINOR = 51;
00107 
00109 // Used to identify the standard field names and the grammar that relates them.
00110 // Will typically be associated with the default namespace in an E57 file.
00111 #define E57_V1_0_URI "http://www.astm.org/COMMIT/E57/2010-e57-v1.0"
00112 
00114 // Minimum and maximum values for integers
00115 const int8_t   E57_INT8_MIN   = -128;
00116 const int8_t   E57_INT8_MAX   = 127;
00117 const int16_t  E57_INT16_MIN  = -32768;
00118 const int16_t  E57_INT16_MAX  = 32767;
00119 const int32_t  E57_INT32_MIN  = -2147483647 - 1;
00120 const int32_t  E57_INT32_MAX  = 2147483647;
00121 const int64_t  E57_INT64_MIN  = -9223372036854775807LL - 1;
00122 const int64_t  E57_INT64_MAX  = 9223372036854775807LL;
00123 const uint8_t  E57_UINT8_MIN  = 0U;
00124 const uint8_t  E57_UINT8_MAX  = 0xffU; /* 255U */
00125 const uint16_t E57_UINT16_MIN = 0U;
00126 const uint16_t E57_UINT16_MAX = 0xffffU; /* 65535U */
00127 const uint32_t E57_UINT32_MIN = 0U;
00128 const uint32_t E57_UINT32_MAX = 0xffffffffU;  /* 4294967295U */
00129 const uint64_t E57_UINT64_MIN = 0ULL;
00130 const uint64_t E57_UINT64_MAX = 0xffffffffffffffffULL; /* 18446744073709551615ULL */
00131 
00132 const float  E57_FLOAT_MIN  = -FLT_MAX;
00133 const float  E57_FLOAT_MAX  = FLT_MAX;
00134 const double E57_DOUBLE_MIN = -DBL_MAX;
00135 const double E57_DOUBLE_MAX = DBL_MAX;
00137 
00138 // Forward references to classes in this header
00139 class Node;
00140 class StructureNode;
00141 class VectorNode;
00142 class SourceDestBuffer;
00143 class CompressedVectorReader;
00144 class CompressedVectorWriter;
00145 class CompressedVectorNode;
00146 class IntegerNode;
00147 class ScaledIntegerNode;
00148 class FloatNode;
00149 class StringNode;
00150 class BlobNode;
00151 class ImageFile;
00152 
00154 //??? Can define operator-> that will make implementation more readable
00155 // Internal implementation files should include e57FoundationImpl.h first which defines symbol E57_INTERNAL_IMPLEMENTATION_ENABLE.
00156 // Normal API users should not define this symbol.
00157 // Basically the internal version allows access to the pointer to the implementation (impl_)
00158 #ifdef E57_INTERNAL_IMPLEMENTATION_ENABLE
00159 #  define E57_OBJECT_IMPLEMENTATION(T)                              \
00160 public:                                                             \
00161     boost::shared_ptr<T##Impl> impl() const {return(impl_);};       \
00162 protected:                                                          \
00163     boost::shared_ptr<T##Impl> impl_;
00164 #else
00165 #  define E57_OBJECT_IMPLEMENTATION(T)                              \
00166 protected:                                                          \
00167     boost::shared_ptr<T##Impl> impl_;
00168 #endif
00169 
00170 
00171 // Forward references to implementation in other headers (so don't have to include E57FoundationImpl.h)
00172 class NodeImpl;
00173 class StructureNodeImpl;
00174 class VectorNodeImpl;
00175 class SourceDestBufferImpl;
00176 class CompressedVectorReaderImpl;
00177 class CompressedVectorWriterImpl;
00178 class CompressedVectorNodeImpl;
00179 class IntegerNodeImpl;
00180 class ScaledIntegerNodeImpl;
00181 class FloatNodeImpl;
00182 class BlobNodeImpl;
00183 class ImageFileImpl;
00184 
00185 class Node {
00186 public:
00187     NodeType    type() const;
00188     bool        isRoot() const;
00189     Node        parent() const;
00190     ustring     pathName() const;
00191     ustring     elementName() const;
00192     ImageFile   destImageFile() const;
00193     bool        isAttached() const;
00194     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00195     void        checkInvariant(bool doRecurse = true, bool doDowncast=true);
00196     bool        operator==(Node n2) const;
00197     bool        operator!=(Node n2) const;
00198 
00200 #ifdef E57_INTERNAL_IMPLEMENTATION_ENABLE
00201     explicit    Node(boost::shared_ptr<NodeImpl>);  // internal use only
00202 #endif
00203 private:   //=================
00204                 Node();                 // No default constructor is defined for Node
00205 protected: //=================
00206     friend class NodeImpl;
00207 
00208     E57_OBJECT_IMPLEMENTATION(Node)  // Internal implementation details, not part of API, must be last in object
00210 };
00211 
00212 class StructureNode {
00213 public:
00214                 StructureNode(ImageFile destImageFile);
00215 
00216     int64_t     childCount() const;
00217     bool        isDefined(const ustring& pathName) const;
00218     Node        get(int64_t index) const;
00219     Node        get(const ustring& pathName) const;
00220     void        set(const ustring& pathName, Node n);
00221 
00222     // Up/Down cast conversion
00223                 operator Node() const;
00224     explicit    StructureNode(const Node& n);
00225 
00226     // Common generic Node functions
00227     bool        isRoot() const;
00228     Node        parent() const;
00229     ustring     pathName() const;
00230     ustring     elementName() const;
00231     ImageFile   destImageFile() const;
00232     bool        isAttached() const;
00233 
00234     // Diagnostic functions:
00235     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00236     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00237 
00239 private:   //=================
00240                 StructureNode();                 // No default constructor is defined for StructureNode
00241 protected: //=================
00242     friend class ImageFile;
00243 
00244                 StructureNode(boost::shared_ptr<StructureNodeImpl> ni);    // internal use only
00245                 StructureNode(boost::weak_ptr<ImageFileImpl> fileParent);  // internal use only
00246 
00247     E57_OBJECT_IMPLEMENTATION(StructureNode)  // Internal implementation details, not part of API, must be last in object
00249 };
00250 
00251 
00252 class VectorNode {
00253 public:
00254     explicit    VectorNode(ImageFile destImageFile, bool allowHeteroChildren = false);
00255 
00256     bool        allowHeteroChildren() const;
00257 
00258     int64_t     childCount() const;
00259     bool        isDefined(const ustring& pathName) const;
00260     Node        get(int64_t index) const;
00261     Node        get(const ustring& pathName) const;
00262     void        append(Node n);
00263 
00264     // Up/Down cast conversion
00265                 operator Node() const;
00266     explicit    VectorNode(const Node& n);
00267 
00268     // Common generic Node functions
00269     bool        isRoot() const;
00270     Node        parent() const;
00271     ustring     pathName() const;
00272     ustring     elementName() const;
00273     ImageFile   destImageFile() const;
00274     bool        isAttached() const;
00275 
00276     // Diagnostic functions:
00277     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00278     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00279 
00281 private:   //=================
00282                 VectorNode();                 // No default constructor is defined for VectorNode
00283 protected: //=================
00284     friend class CompressedVectorNode;
00285 
00286                 VectorNode(boost::shared_ptr<VectorNodeImpl> ni);  // internal use only
00287 
00288     E57_OBJECT_IMPLEMENTATION(VectorNode)  // Internal implementation details, not part of API, must be last in object
00290 };
00291 
00292 class SourceDestBuffer {
00293 public:
00294     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, int8_t* b,   const size_t capacity,
00295                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(int8_t));
00296     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, uint8_t* b,  const size_t capacity,
00297                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(uint8_t));
00298     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, int16_t* b,  const size_t capacity,
00299                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(int16_t));
00300     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, uint16_t* b, const size_t capacity,
00301                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(uint16_t));
00302     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, int32_t* b,  const size_t capacity,
00303                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(int32_t));
00304     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, uint32_t* b, const size_t capacity,
00305                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(uint32_t));
00306     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, int64_t* b,  const size_t capacity,
00307                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(int64_t));
00308     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, bool* b,     const size_t capacity,
00309                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(bool));
00310     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, float* b,    const size_t  capacity,
00311                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(float));
00312     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, double* b,   const size_t capacity,
00313                      bool doConversion = false, bool doScaling = false, size_t stride = sizeof(double));
00314     SourceDestBuffer(ImageFile destImageFile, const ustring pathName, std::vector<ustring>* b);
00315 
00316     ustring         pathName() const;
00317     enum MemoryRepresentation  memoryRepresentation() const;
00318     size_t          capacity() const;
00319     bool            doConversion() const;
00320     bool            doScaling() const;
00321     size_t          stride() const;
00322 
00323     // Diagnostic functions:
00324     void            dump(int indent = 0, std::ostream& os = std::cout) const;
00325     void            checkInvariant(bool doRecurse = true);
00326 
00328 private:   //=================
00329                     SourceDestBuffer();                 // No default constructor is defined for SourceDestBuffer
00330 
00331 protected: //=================
00332 
00333     E57_OBJECT_IMPLEMENTATION(SourceDestBuffer)  // Internal implementation details, not part of API, must be last in object
00335 };
00336 
00337 class CompressedVectorReader {
00338 public:
00339     unsigned    read();
00340     unsigned    read(std::vector<SourceDestBuffer>& dbufs);
00341     void        seek(int64_t recordNumber); // !!! not implemented yet
00342     void        close();
00343     bool        isOpen();
00344     CompressedVectorNode compressedVectorNode() const;
00345 
00346     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00347     void        checkInvariant(bool doRecurse = true);
00348 
00350 private:   //=================
00351                 CompressedVectorReader();          // No default constructor is defined for CompressedVectorReader
00352 protected: //=================
00353     friend class CompressedVectorNode;
00354 
00355                 CompressedVectorReader(boost::shared_ptr<CompressedVectorReaderImpl> ni);
00356 
00357     E57_OBJECT_IMPLEMENTATION(CompressedVectorReader)  // Internal implementation details, not part of API, must be last in object
00359 };
00360 
00361 class CompressedVectorWriter {
00362 public:
00363     void        write(const size_t requestedRecordCount);
00364     void        write(std::vector<SourceDestBuffer>& sbufs, const size_t requestedRecordCount);
00365     void        close();
00366     bool        isOpen();
00367     CompressedVectorNode compressedVectorNode() const;
00368 
00369     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00370     void        checkInvariant(bool doRecurse = true);
00371 
00373 private:   //=================
00374                 CompressedVectorWriter();          // No default constructor is defined for CompressedVectorWriter
00375 protected: //=================
00376     friend class CompressedVectorNode;
00377 
00378                 CompressedVectorWriter(boost::shared_ptr<CompressedVectorWriterImpl> ni);
00379 
00380     E57_OBJECT_IMPLEMENTATION(CompressedVectorWriter)  // Internal implementation details, not part of API, must be last in object
00382 };
00383 
00384 class CompressedVectorNode {
00385 public:
00386     explicit    CompressedVectorNode(ImageFile destImageFile, Node prototype, VectorNode codecs);
00387 
00388     int64_t     childCount() const;
00389     Node        prototype() const;
00390     VectorNode  codecs() const;
00391 
00392     // Iterators
00393     CompressedVectorWriter writer(std::vector<SourceDestBuffer>& sbufs);
00394     CompressedVectorReader reader(const std::vector<SourceDestBuffer>& dbufs);
00395 
00396     // Up/Down cast conversion
00397                 operator Node() const;
00398     explicit    CompressedVectorNode(const Node& n);
00399 
00400     // Common generic Node functions
00401     bool        isRoot() const;
00402     Node        parent() const;
00403     ustring     pathName() const;
00404     ustring     elementName() const;
00405     ImageFile   destImageFile() const;
00406     bool        isAttached() const;
00407 
00408     // Diagnostic functions:
00409     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00410     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00411 
00413 private:   //=================
00414                 CompressedVectorNode();           // No default constructor is defined for CompressedVectorNode
00415 protected: //=================
00416     friend class CompressedVectorReader;
00417     friend class CompressedVectorWriter;
00418     friend class E57XmlParser;
00419 
00420                 CompressedVectorNode(boost::shared_ptr<CompressedVectorNodeImpl> ni);  // internal use only
00421 
00422     E57_OBJECT_IMPLEMENTATION(CompressedVectorNode)  // Internal implementation details, not part of API, must be last in object
00424 };
00425 
00426 class IntegerNode {
00427 public:
00428     explicit    IntegerNode(ImageFile destImageFile, int64_t value = 0, int64_t minimum = E57_INT64_MIN, int64_t maximum = E57_INT64_MAX);
00429 
00430     int64_t     value() const;
00431     int64_t     minimum() const;
00432     int64_t     maximum() const;
00433 
00434     // Up/Down cast conversion
00435                 operator Node() const;
00436     explicit    IntegerNode(const Node& n);
00437 
00438     // Common generic Node functions
00439     bool        isRoot() const;
00440     Node        parent() const;
00441     ustring     pathName() const;
00442     ustring     elementName() const;
00443     ImageFile   destImageFile() const;
00444     bool        isAttached() const;
00445 
00446     // Diagnostic functions:
00447     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00448     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00449 
00451 private:   //=================
00452                 IntegerNode();                 // No default constructor is defined for IntegerNode
00453 protected: //=================
00454 
00455                 IntegerNode(boost::shared_ptr<IntegerNodeImpl> ni);  // internal use only
00456 
00457     E57_OBJECT_IMPLEMENTATION(IntegerNode)  // Internal implementation details, not part of API, must be last in object
00459 };
00460 
00461 class ScaledIntegerNode {
00462 public:
00463     explicit    ScaledIntegerNode(ImageFile destImageFile, int64_t value, int64_t minimum, int64_t maximum,
00464                                   double scale = 1.0, double offset = 0.0);
00465     explicit    ScaledIntegerNode(ImageFile destImageFile, int value, int64_t minimum, int64_t maximum,
00466                                   double scale = 1.0, double offset = 0.0);
00467     explicit    ScaledIntegerNode(ImageFile destImageFile, int value, int minimum, int maximum,
00468                                   double scale = 1.0, double offset = 0.0);
00469     explicit    ScaledIntegerNode(ImageFile destImageFile, double scaledValue, double scaledMinimum, double scaledMaximum,
00470                                   double scale = 1.0, double offset = 0.0);     //Added by SC
00471 
00472     int64_t     rawValue() const;
00473     double      scaledValue() const;
00474     int64_t     minimum() const;
00475     double      scaledMinimum() const;  //Added by SC
00476     int64_t     maximum() const;
00477     double      scaledMaximum() const;  //Added by SC
00478     double      scale() const;
00479     double      offset() const;
00480 
00481     // Up/Down cast conversion
00482                 operator Node() const;
00483     explicit    ScaledIntegerNode(const Node& n);
00484 
00485     // Common generic Node functions
00486     bool        isRoot() const;
00487     Node        parent() const;
00488     ustring     pathName() const;
00489     ustring     elementName() const;
00490     ImageFile   destImageFile() const;
00491     bool        isAttached() const;
00492 
00493     // Diagnostic functions:
00494     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00495     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00496 
00498 private:   //=================
00499                 ScaledIntegerNode();                 // No default constructor is defined for ScaledIntegerNode
00500 protected: //=================
00501 
00502                 ScaledIntegerNode(boost::shared_ptr<ScaledIntegerNodeImpl> ni);  // internal use only
00503 
00504     E57_OBJECT_IMPLEMENTATION(ScaledIntegerNode)  // Internal implementation details, not part of API, must be last in object
00506 };
00507 
00508 class FloatNode {
00509 public:
00510     explicit    FloatNode(ImageFile destImageFile, double value = 0.0, FloatPrecision precision = E57_DOUBLE,
00511                           double minimum = E57_DOUBLE_MIN, double  maximum = E57_DOUBLE_MAX);
00512 
00513     double      value() const;
00514     FloatPrecision precision() const;
00515     double      minimum() const;
00516     double      maximum() const;
00517 
00518     // Up/Down cast conversion
00519                 operator Node() const;
00520     explicit    FloatNode(const Node& n);
00521 
00522     // Common generic Node functions
00523     bool        isRoot() const;
00524     Node        parent() const;
00525     ustring     pathName() const;
00526     ustring     elementName() const;
00527     ImageFile   destImageFile() const;
00528     bool        isAttached() const;
00529 
00530     // Diagnostic functions:
00531     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00532     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00533 
00535 private:   //=================
00536                 FloatNode();                 // No default constructor is defined for FloatNode
00537 protected: //=================
00538 
00539                 FloatNode(boost::shared_ptr<FloatNodeImpl> ni);  // internal use only
00540 
00541     E57_OBJECT_IMPLEMENTATION(FloatNode)  // Internal implementation details, not part of API, must be last in object
00543 };
00544 
00545 class StringNodeImpl;
00546 class StringNode {
00547 public:
00548     explicit    StringNode(ImageFile destImageFile, const ustring value = "");
00549 
00550     ustring     value() const;
00551 
00552     // Up/Down cast conversion
00553                 operator Node() const;
00554     explicit    StringNode(const Node& n);
00555 
00556     // Common generic Node functions
00557     bool        isRoot() const;
00558     Node        parent() const;
00559     ustring     pathName() const;
00560     ustring     elementName() const;
00561     ImageFile   destImageFile() const;
00562     bool        isAttached() const;
00563 
00564     // Diagnostic functions:
00565     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00566     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00567 
00569 private:   //=================
00570                 StringNode();                 // No default constructor is defined for StringNode
00571 protected: //=================
00572     friend class StringNodeImpl;
00573                 StringNode(boost::shared_ptr<StringNodeImpl> ni);  // internal use only
00574 
00575     E57_OBJECT_IMPLEMENTATION(StringNode)  // Internal implementation details, not part of API, must be last in object
00577 };
00578 
00579 class BlobNode {
00580 public:
00581     explicit    BlobNode(ImageFile destImageFile, int64_t byteCount);
00582 
00583     int64_t     byteCount() const;
00584     void        read(uint8_t* buf,  int64_t start, size_t byteCount);
00585     void        write(uint8_t* buf, int64_t start, size_t byteCount);
00586 
00587     // Up/Down cast conversion
00588                 operator Node() const;
00589     explicit    BlobNode(const Node& n);
00590 
00591     // Common generic Node functions
00592     bool        isRoot() const;
00593     Node        parent() const;
00594     ustring     pathName() const;
00595     ustring     elementName() const;
00596     ImageFile   destImageFile() const;
00597     bool        isAttached() const;
00598 
00599     // Diagnostic functions:
00600     void        dump(int indent = 0, std::ostream& os = std::cout) const;
00601     void        checkInvariant(bool doRecurse = true, bool doUpcast=true);
00602 
00604 private:   //=================
00605                 BlobNode();                 // No default constructor is defined for BlobNode
00606 protected: //=================
00607     friend class E57XmlParser;
00608 
00609                 BlobNode(boost::shared_ptr<BlobNodeImpl> ni);       // internal use only
00610 
00611                 // Internal use only, create blob already in a file
00612                 BlobNode(ImageFile destImageFile, int64_t fileOffset, int64_t length);
00613 
00614     E57_OBJECT_IMPLEMENTATION(BlobNode)  // Internal implementation details, not part of API, must be last in object
00616 };
00617 
00618 class ImageFile {
00619 public:
00620                     ImageFile(const ustring& fname, const ustring& mode, const ustring& configuration = "");
00621     StructureNode   root() const;
00622     void            close();
00623     void            cancel();
00624     bool            isOpen() const;
00625     bool            isWritable() const;
00626     ustring         fileName() const;
00627     int             writerCount() const;
00628     int             readerCount() const;
00629 
00630     // Manipulate registered extensions in the file
00631     void            extensionsAdd(const ustring& prefix, const ustring& uri);
00632     bool            extensionsLookupPrefix(const ustring& prefix, ustring& uri) const;
00633     bool            extensionsLookupUri(const ustring& uri, ustring& prefix) const;
00634     size_t          extensionsCount() const;
00635     ustring         extensionsPrefix(const size_t index) const;
00636     ustring         extensionsUri(const size_t index) const;
00637 
00638     // Field name functions:
00639     bool            isElementNameExtended(const ustring& elementName) const;
00640     void            elementNameParse(const ustring& elementName, ustring& prefix, ustring& localPart) const;
00641 
00642     // Diagnostic functions:
00643     void            dump(int indent = 0, std::ostream& os = std::cout) const;
00644     void            checkInvariant(bool doRecurse = true);
00645     bool            operator==(ImageFile imf2) const;
00646     bool            operator!=(ImageFile imf2) const;
00647 
00649 private:   //=================
00650                     ImageFile();                 // No default constructor is defined for ImageFile
00651                     ImageFile(double);           // Give a second dummy constructor, better error msg for: ImageFile(0)
00652 protected: //=================
00653     //??? workaround?
00654     friend class Node;
00655     friend class StructureNode;
00656     friend class VectorNode;
00657     friend class CompressedVectorNode;
00658     friend class IntegerNode;
00659     friend class ScaledIntegerNode;
00660     friend class FloatNode;
00661     friend class StringNode;
00662     friend class BlobNode;
00663 
00664                     ImageFile(boost::shared_ptr<ImageFileImpl> imfi);  // internal use only
00665 
00666     E57_OBJECT_IMPLEMENTATION(ImageFile)  // Internal implementation details, not part of API, must be last in object
00668 };
00669 
00671 enum ErrorCode {
00672     /*
00673      * N.B.  *** When changing error strings here, remember to update the error strings in E57Foundation.cpp ****
00674      */
00675     E57_SUCCESS                                 = 0,  
00676     E57_ERROR_BAD_CV_HEADER                     = 1,  
00677     E57_ERROR_BAD_CV_PACKET                     = 2,  
00678     E57_ERROR_CHILD_INDEX_OUT_OF_BOUNDS         = 3,  
00679     E57_ERROR_SET_TWICE                         = 4,  
00680     E57_ERROR_HOMOGENEOUS_VIOLATION             = 5,  
00681     E57_ERROR_VALUE_NOT_REPRESENTABLE           = 6,  
00682     E57_ERROR_SCALED_VALUE_NOT_REPRESENTABLE    = 7,  
00683     E57_ERROR_REAL64_TOO_LARGE                  = 8,  
00684     E57_ERROR_EXPECTING_NUMERIC                 = 9,  
00685     E57_ERROR_EXPECTING_USTRING                 = 10, 
00686     E57_ERROR_INTERNAL                          = 11, 
00687     E57_ERROR_BAD_XML_FORMAT                    = 12, 
00688     E57_ERROR_XML_PARSER                        = 13, 
00689     E57_ERROR_BAD_API_ARGUMENT                  = 14, 
00690     E57_ERROR_FILE_IS_READ_ONLY                 = 15, 
00691     E57_ERROR_BAD_CHECKSUM                      = 16, 
00692     E57_ERROR_OPEN_FAILED                       = 17, 
00693     E57_ERROR_CLOSE_FAILED                      = 18, 
00694     E57_ERROR_READ_FAILED                       = 19, 
00695     E57_ERROR_WRITE_FAILED                      = 20, 
00696     E57_ERROR_LSEEK_FAILED                      = 21, 
00697     E57_ERROR_PATH_UNDEFINED                    = 22, 
00698     E57_ERROR_BAD_BUFFER                        = 23, 
00699     E57_ERROR_NO_BUFFER_FOR_ELEMENT             = 24, 
00700     E57_ERROR_BUFFER_SIZE_MISMATCH              = 25, 
00701     E57_ERROR_BUFFER_DUPLICATE_PATHNAME         = 26, 
00702     E57_ERROR_BAD_FILE_SIGNATURE                = 27, 
00703     E57_ERROR_UNKNOWN_FILE_VERSION              = 28, 
00704     E57_ERROR_BAD_FILE_LENGTH                   = 29, 
00705     E57_ERROR_XML_PARSER_INIT                   = 30, 
00706     E57_ERROR_DUPLICATE_NAMESPACE_PREFIX        = 31, 
00707     E57_ERROR_DUPLICATE_NAMESPACE_URI           = 32, 
00708     E57_ERROR_BAD_PROTOTYPE                     = 33, 
00709     E57_ERROR_BAD_CODECS                        = 34, 
00710     E57_ERROR_VALUE_OUT_OF_BOUNDS               = 35, 
00711     E57_ERROR_CONVERSION_REQUIRED               = 36, 
00712     E57_ERROR_BAD_PATH_NAME                     = 37, 
00713     E57_ERROR_NOT_IMPLEMENTED                   = 38, 
00714     E57_ERROR_BAD_NODE_DOWNCAST                 = 39, 
00715     E57_ERROR_WRITER_NOT_OPEN                   = 40, 
00716     E57_ERROR_READER_NOT_OPEN                   = 41, 
00717     E57_ERROR_NODE_UNATTACHED                   = 42, 
00718     E57_ERROR_ALREADY_HAS_PARENT                = 43, 
00719     E57_ERROR_DIFFERENT_DEST_IMAGEFILE          = 44, 
00720     E57_ERROR_IMAGEFILE_NOT_OPEN                = 45, 
00721     E57_ERROR_BUFFERS_NOT_COMPATIBLE            = 46, 
00722     E57_ERROR_TOO_MANY_WRITERS                  = 47, 
00723     E57_ERROR_TOO_MANY_READERS                  = 48, 
00724     E57_ERROR_BAD_CONFIGURATION                 = 49, 
00725     E57_ERROR_INVARIANCE_VIOLATION              = 50  
00726     /*
00727      * N.B.  *** When changing error strings here, remember to update the error strings in E57Foundation.cpp ****
00728      */
00729 };
00730 
00731 class E57Exception : public std::exception {
00732 public:
00733     virtual void        report(const char* reportingFileName=NULL, int reportingLineNumber=0, const char* reportingFunctionName=NULL, std::ostream& os = std::cout) const;
00734     virtual ErrorCode   errorCode() const;
00735     virtual ustring     context() const;
00736     virtual const char* what() const throw();
00737 
00738     // For debugging purposes:
00739     virtual const char* sourceFileName() const;
00740     virtual const char* sourceFunctionName() const;
00741     virtual int         sourceLineNumber() const;
00742 
00744     E57Exception(ErrorCode ecode, const ustring context,
00745                  const char* srcFileName = NULL, int srcLineNumber = 0, const char* srcFunctionName = NULL);
00746     ~E57Exception() throw() {};
00747 
00748 private:   //=================
00749                 E57Exception();                 // No default constructor is defined for E57Exception
00750 protected: //=================
00751     ErrorCode   errorCode_;
00752     ustring     context_;
00753     const char* sourceFileName_;
00754     const char* sourceFunctionName_;
00755     int         sourceLineNumber_;
00757 };
00758 
00759 class E57Utilities {
00760 public:
00761     // Constructor (does nothing for now)
00762                 E57Utilities(const ustring& /*configuration*/ = "") {};
00763 
00764     // Get latest version of ASTM standard supported, and library id string
00765     void        getVersions(int& astmMajor, int& astmMinor, ustring& libraryId);
00766 
00767     // Error code translation
00768     ustring     errorCodeToString(ErrorCode ecode);
00769 
00770     // Direct read of XML representation in E57 file
00771     int64_t     rawXmlLength(const ustring& fname);
00772     void        rawXmlRead(const ustring& fname, uint8_t* buf, int64_t start, size_t byteCount);
00773 };
00774 
00775 #ifndef DOXYGEN
00776 }  // end namespace e57
00777 #endif
00778 
00779 #endif // E57FOUNDATION_H_INCLUDED
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines