/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _METAFILESTREAMBASE_INCLUDED_ #define _METAFILESTREAMBASE_INCLUDED_ #include "TD_PackPush.h" #include "OdaCommon.h" #include "OdAlloc.h" #include "OdString.h" #include "OdArray.h" #include "CmColorBase.h" #include "OdCharMapper.h" #include "Ge/GePoint2d.h" #include "Ge/GePoint3d.h" #include "Ge/GeVector2d.h" #include "Ge/GeVector3d.h" #include "Ge/GeQuaternion.h" #include "Ge/GeMatrix2d.h" #include "Ge/GeMatrix3d.h" class OdBaseMetafileContainerReader; class OdBaseMetafileContainerWriter; /** \details This class is a base memory container for the metafile contents interface. Library: Source code provided. */ class OdBaseMetafileContainer { public: /** \details Returns size of entire allocated memory. \returns Allocated memory in bytes. */ virtual OdUInt32 size() const = 0; /** \details Returns pointer to the data in memory at the specified position. \param pos [in] Position in memory. \returns Pointer to the data in memory. */ virtual const void *memoryPtr(OdUInt32 pos) const = 0; /** \details Allocates additional memory. \param size [in] Size of additional memory to allocate. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ virtual void inflateBuffer(OdUInt32 size, bool lockPage = true) = 0; /** \details Writes data to memory. \param pos [in] Offset from this memory container. \param data [in] Pointer to an array of data to write. \param size [in] Size of the data array. */ virtual void writeTo(OdUInt32 pos, const void *data, OdUInt32 size) = 0; /** \details Reads data from memory. \param pos [in] Offset from this memory container. \param data [out] Receives data. \param size [in] Size of the data array. */ virtual void readFrom(OdUInt32 pos, void *data, OdUInt32 size) const = 0; /** \details Truncates allocations to use optimal memory size. \param uSize [in] Optimal memory size. \remarks Call after all writing operations are completed. */ virtual void optimizeMemory(OdUInt32 uSize) = 0; /** \details Creates a metafile container reader. \returns Pointer to the created instance that provides various read-related operations for a metafile container, such as getting current position, determining size, reading data from the container, etc. */ virtual OdBaseMetafileContainerReader *createReader() const = 0; /** \details Creates a metafile container writer. \returns Pointer to the created instance that provides various write-related operations for a metafile container, such as determining initial size, grow size, writing data to a container, etc. */ virtual OdBaseMetafileContainerWriter *createWriter() const = 0; }; /** \details This class is a flat memory container for metafile contents. Library: Source code provided. */ class OdFlatMetafileContainer : public OdBaseMetafileContainer { friend class OdFlatMetafileContainerWriter; friend class OdFlatMetafileContainerReader; protected: OdUInt8 *m_pData; OdUInt32 m_uLength; public: OdUInt32 m_nRefs; public: /** \details Default constructor for the OdFlatMetafileContainer class. */ OdFlatMetafileContainer() : m_pData(NULL), m_uLength(0), m_nRefs(0) { } /** \details Destructor for the OdFlatMetafileContainer class. Clear the container. */ ~OdFlatMetafileContainer() { clearFlatContainer(); } /** \details Clear the container. */ void clearFlatContainer() { if (m_pData) { ::odrxFree(m_pData); m_pData = NULL; } m_uLength = 0; } /** \details Returns the size of the metafile container. \returns Size of the metafile container in bytes. */ OdUInt32 size() const override { return m_uLength; } /** \details Returns pointer to the data in memory at the specified position. \param pos [in] Position in memory. \returns Pointer to the data in memory. */ const void *memoryPtr(OdUInt32 pos) const override { return m_pData + pos; } /** \details Allocates additional memory. \param size [in] Size of additional memory to allocate. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ void inflateBuffer(OdUInt32 size, bool /*lockPage*/ = true) override { if (m_pData) m_pData = (OdUInt8*)::odrxRealloc(m_pData, m_uLength + size, m_uLength); else m_pData = (OdUInt8*)::odrxAlloc(size); if (m_pData == NULL) throw OdError(eOutOfMemory); m_uLength += size; } /** \details Writes data to memory. \param pos [in] Offset from this memory container. \param data [in] Pointer to an array of data to write. \param size [in] Size of the data array. */ void writeTo(OdUInt32 pos, const void *data, OdUInt32 size) override { ::memcpy(m_pData + pos, data, size); } /** \details Reads data from memory. \param pos [in] Offset from this memory container. \param data [out] Receives data. \param size [in] Size of the data array. */ void readFrom(OdUInt32 pos, void *data, OdUInt32 size) const override { ::memcpy(data, m_pData + pos, size); } /** \details Truncates allocations to use optimal memory size. \param uSize [in] Optimal memory size. \remarks Call after all writing operations are completed. */ void optimizeMemory(OdUInt32 uSize) override { if (m_uLength != uSize) { m_pData = (OdUInt8*)::odrxRealloc(m_pData, uSize, m_uLength); m_uLength = uSize; } } virtual void exchangeData(OdFlatMetafileContainer &sndCnt) { OdIntPtr temp = (OdIntPtr)m_pData; m_pData = sndCnt.m_pData; sndCnt.m_pData = (OdUInt8*)temp; temp = (OdIntPtr)m_uLength; m_uLength = sndCnt.m_uLength; sndCnt.m_uLength = (OdUInt32)temp; } /** \details This structure represents a gap in a metafile where there is no data. */ struct Gap { OdUInt32 m_from, m_to; //Gap from, gap to Gap *m_pNextGap; //Pointer to the next gap /** \details Default constructor for the Gap struct. */ Gap() : m_from(0), m_to(0), m_pNextGap(NULL) { } }; /** \details Creates a new flat metafile container. \returns Pointer to a new OdFlatMetafileContainer instance. */ virtual OdFlatMetafileContainer *createMe() const { return new OdFlatMetafileContainer; } /** \details Clones the stream data with gaps elimination. \param pGaps [in] Pointer to gap in the stream. \returns Pointer to a the cloned OdFlatMetafileContainer instance without gaps. */ virtual OdFlatMetafileContainer *clone(const Gap *pGaps = NULL) const; /** \details Creates a metafile container reader. \returns Pointer to the created instance that provides various read-related operations for a metafile container, such as getting current position, determining size, reading data from the container, etc. */ OdBaseMetafileContainerReader *createReader() const override; /** \details Creates a metafile container writer. \returns Pointer to the created instance that provides various write-related operations for a metafile container, such as determining initial size, grow size, writing data to a container, etc. */ OdBaseMetafileContainerWriter *createWriter() const override; }; /** \details . Library: Source code provided. */ class OdBaseMetafileContainerIOBase { protected: OdBaseMetafileContainer *m_pContainer; public: /** \details Default constructor for the OdBaseMetafileContainerIOBase class. */ OdBaseMetafileContainerIOBase() : m_pContainer(NULL) { } /** \details Constructor for the OdBaseMetafileContainerIOBase class. Creates an instance from the specified metafile container. \param pContainer [in] Pointer to a metafile container. */ OdBaseMetafileContainerIOBase(OdBaseMetafileContainer *pContainer) : m_pContainer(pContainer) { } /** \details Destructor for the OdBaseMetafileContainerIOBase class. */ virtual ~OdBaseMetafileContainerIOBase() { } // Mac warn /** \details Sets a container for this object. \param pContainer [in] Pointer to base metafile container. */ virtual void setContainer(OdBaseMetafileContainer *pContainer) { m_pContainer = pContainer; } /** \details Returns container associated with this object. \returns Pointer to base metafile container associated with this object. */ virtual OdBaseMetafileContainer *container() const { return m_pContainer; } /** \details Creates a new flat metafile container. \returns Pointer to the created metafile container. */ virtual OdBaseMetafileContainer *createContainer() const = 0; /** \details Returns size of entire allocated memory. \returns Allocated memory in bytes. */ virtual OdUInt32 size() const = 0; /** \details Returns current position in the container. \returns Position in memory. */ virtual OdUInt32 position() const = 0; /** \details Resets current position. \param delta [in] Move distance. \param forward [in] Flag that specifies seek direction. It true - seeks forward, if false - seeks backwards. */ virtual void seek(OdUInt32 delta, bool forward = true) = 0; }; /** \details . Library: Source code provided. */ class OdBaseMetafileContainerWriter : public /*virtual*/ OdBaseMetafileContainerIOBase { public: /** \details Default constructor for the OdBaseMetafileContainerWriter class. */ OdBaseMetafileContainerWriter() : OdBaseMetafileContainerIOBase() { } /** \details Constructor for the OdBaseMetafileContainerWriter class. Creates an instance from the specified metafile container. \param pContainer [in] Pointer to a metafile container. */ OdBaseMetafileContainerWriter(OdBaseMetafileContainer *pContainer) : OdBaseMetafileContainerIOBase(pContainer) { } /** \details Reserves memory for write operation. \param size [in] Memory size to reserve. \param moveCaret [in] Flag that specifies whether to change current caret position. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ virtual void reserve(OdUInt32 size, bool moveCaret = true, bool lockPage = true) = 0; /** \details Writes data to memory. \param data [in] Pointer to an array of data to write. \param size [in] Size of the data array. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ virtual void write(const void *data, OdUInt32 size, bool lockPage = true) = 0; /** \details Truncates allocations to use optimal memory size. \remarks Call after all writing operations are completed. */ virtual void completeWriting() = 0; }; /** \details . Library: Source code provided. */ class OdBaseMetafileContainerReader : public /*virtual*/ OdBaseMetafileContainerIOBase { public: /** \details Default constructor for the OdBaseMetafileContainerReader class. */ OdBaseMetafileContainerReader() : OdBaseMetafileContainerIOBase() { } /** \details Constructor for the OdBaseMetafileContainerWriter class. Creates an instance from the specified metafile container. \param pContainer [in] Pointer to a metafile container. */ OdBaseMetafileContainerReader(OdBaseMetafileContainer *pContainer) : OdBaseMetafileContainerIOBase(pContainer) { } /** \details Returns pointer to the data in memory at current caret position. \returns Pointer to the data in memory. */ virtual const void *memoryPtr() const = 0; /** \details Reads data from memory. \param data [out] Receives data. \param size [in] Size of the data array. */ virtual void read(void *data, OdUInt32 size) const = 0; /** \details Checks whether caret at the end of data. \returns true if caret is positioned at the end of file, false otherwise. */ virtual bool isEof() const = 0; }; /** \details . Library: Source code provided. */ class OdFlatMetafileContainerWriter : public OdBaseMetafileContainerWriter { protected: OdUInt32 m_uCaret; OdUInt32 m_uLength; // OdUInt32 m_uInitSize; OdUInt32 m_uGrowSize; public: #define OD_FLATMETAFILECONTAINERWRITER_DEF_INITSIZE 256 #define OD_FLATMETAFILECONTAINERWRITER_DEF_GROWSIZE 64 /** \details Constructor for the OdFlatMetafileContainerWriter class. Creates an instance with defined initial container size and grow container size. \param uInitSize [in] Initial size. \param uGrowSize [in] Grow size. */ OdFlatMetafileContainerWriter(OdUInt32 uInitSize = OD_FLATMETAFILECONTAINERWRITER_DEF_INITSIZE, OdUInt32 uGrowSize = OD_FLATMETAFILECONTAINERWRITER_DEF_GROWSIZE) : OdBaseMetafileContainerWriter(), m_uCaret(0), m_uLength(0), m_uInitSize(uInitSize), m_uGrowSize(uGrowSize) { } /** \details Constructor for the OdFlatMetafileContainerWriter class. Creates an instance with defined container, initial container size and grow container size. \param pContainer [in] Pointer to metafile container. \param uInitSize [in] Initial size. \param uGrowSize [in] Grow size. */ OdFlatMetafileContainerWriter(OdBaseMetafileContainer *pContainer, OdUInt32 uInitSize = OD_FLATMETAFILECONTAINERWRITER_DEF_INITSIZE, OdUInt32 uGrowSize = OD_FLATMETAFILECONTAINERWRITER_DEF_GROWSIZE) : OdBaseMetafileContainerWriter(pContainer), m_uCaret(0), m_uInitSize(uInitSize), m_uGrowSize(uGrowSize) { m_uLength = pContainer->size(); } /** \details Sets the initial size of container. \param uInitSize [in] Initial size. */ void setInitSize(OdUInt32 uInitSize) { m_uInitSize = uInitSize; } /** \details Returns initial size of container. \returns Initial size of container. */ OdUInt32 initSize() const { return m_uInitSize; } /** \details Sets the grow size of container. \param uGrowSize [in] Grow size. */ void setGrowSize(OdUInt32 uGrowSize) { m_uGrowSize = uGrowSize; } /** \details Returns grow size of container. \returns Grow size of container. */ OdUInt32 growSize() const { return m_uGrowSize; } /** \details Sets a container for this writer. \param pContainer [in] Pointer to a metafile container. */ void setContainer(OdBaseMetafileContainer *pContainer) override { OdBaseMetafileContainerIOBase::setContainer(pContainer); if (pContainer) m_uLength = pContainer->size(); m_uCaret = 0; } /** \details Creates a metafile container. \returns Pointer to a new metafile container. */ OdBaseMetafileContainer *createContainer() const override { return new OdFlatMetafileContainer(); } /** \details Creates a flat metafile container from existing container. \returns Pointer to a flat metafile container. */ OdFlatMetafileContainer *flatContainer() const { return static_cast(container()); } /** \details Returns the size of the metafile container. \returns Size of the metafile container in bytes. */ OdUInt32 size() const override { return m_uLength; } /** \details Returns current position in the container. \returns Position in memory. */ OdUInt32 position() const override { return m_uCaret; } /** \details Resets current position. \param delta [in] Move distance. \param forward [in] Flag that specifies seek direction. It true - seeks forward, if false - seeks backwards. */ void seek(OdUInt32 delta, bool forward = true) override { if (delta) { if (forward) { if (m_uCaret + delta < m_uLength) m_uCaret += delta; else m_uCaret = m_uLength; } else { if (delta < m_uCaret) m_uCaret -= delta; else m_uCaret = 0; } } } /** \details Reserves memory for write operation. \param size [in] Memory size to reserve. \param moveCaret [in] Flag that specifies whether to change current caret position. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ void reserve(OdUInt32 size, bool moveCaret, bool lockPage = true) override { if (size + m_uCaret > m_uLength) { OdUInt32 newLen = m_uCaret + size; if (newLen > flatContainer()->size()) { OdUInt32 swapSize = m_uInitSize; if (newLen > swapSize) swapSize = ((newLen - m_uInitSize) / m_uGrowSize + 1) * m_uGrowSize + m_uInitSize; flatContainer()->inflateBuffer(swapSize - flatContainer()->size(), lockPage); } m_uLength = m_uCaret + size; } if (moveCaret) m_uCaret += size; } /** \details Write data to memory. \param data [in] Pointer to an array of data to write. \param size [in] Size of the data array. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ void write(const void *data, OdUInt32 size, bool lockPage = true) override { if (size) { reserve(size, false, lockPage); flatContainer()->writeTo(m_uCaret, data, size); m_uCaret += size; } } /** \details Truncates allocations to use optimal memory size. \remarks Call after all writing operations are completed. */ void completeWriting() override { flatContainer()->optimizeMemory(m_uLength); } }; /** \details . Library: Source code provided. */ class OdFlatMetafileContainerReader : public OdBaseMetafileContainerReader { protected: mutable OdUInt32 m_uCaret; public: /** \details Default constructor for the OdFlatMetafileContainerReader class. */ OdFlatMetafileContainerReader() : OdBaseMetafileContainerReader(), m_uCaret(0) { } /** \details Constructor for the OdFlatMetafileContainerReader class. Creates an instance from the specified metafile container. \param pContainer [in] Pointer to base metafile container. */ OdFlatMetafileContainerReader(OdBaseMetafileContainer *pContainer) : OdBaseMetafileContainerReader(pContainer), m_uCaret(0) { } /** \details Sets a container for this reader. \param pContainer [in] Pointer to a metafile container. */ void setContainer(OdBaseMetafileContainer *pContainer) override { OdBaseMetafileContainerIOBase::setContainer(pContainer); m_uCaret = 0; } /** \details Creates a metafile container. \returns Pointer to a new metafile container. */ OdBaseMetafileContainer *createContainer() const override { return new OdFlatMetafileContainer(); } /** \details Creates a flat metafile container from existing container. \returns Pointer to a flat metafile container. */ OdFlatMetafileContainer *flatContainer() const { return static_cast(container()); } /** \details Returns the size of the metafile container. \returns Size of the metafile container in bytes. */ OdUInt32 size() const override { return flatContainer()->size(); } /** \details Returns current position in the container. \returns Position in memory. */ OdUInt32 position() const override { return m_uCaret; } /** \details Resets current position. \param delta [in] Move distance. \param forward [in] Flag that specifies seek direction. It true - seeks forward, if false - seeks backwards. */ void seek(OdUInt32 delta, bool forward = true) override { if (delta) { if (forward) { if (m_uCaret + delta < flatContainer()->size()) m_uCaret += delta; else m_uCaret = flatContainer()->size(); } else { if (delta < m_uCaret) m_uCaret -= delta; else m_uCaret = 0; } } } /** \details Returns pointer to the data in memory at current caret position. \returns Pointer to the data in memory. */ const void *memoryPtr() const override { return flatContainer()->memoryPtr(m_uCaret); } /** \details Reads data from memory. \param data [out] Receives data. \param size [in] Size of the data array. */ void read(void *data, OdUInt32 size) const override { flatContainer()->readFrom(m_uCaret, data, size); m_uCaret += size; } /** \details Checks whether caret at the end of data. \returns true if caret is positioned at the end of file, false otherwise. */ bool isEof() const override { return m_uCaret >= size(); } }; inline OdBaseMetafileContainerReader *OdFlatMetafileContainer::createReader() const { return new OdFlatMetafileContainerReader(); } inline OdBaseMetafileContainerWriter *OdFlatMetafileContainer::createWriter() const { return new OdFlatMetafileContainerWriter(); } inline OdFlatMetafileContainer *OdFlatMetafileContainer::clone(const Gap *pGaps) const { OdFlatMetafileContainer *pClone = createMe(); const Gap defGap; if (!pGaps) pGaps = &defGap; OdUInt32 nGapsSpace = pGaps->m_to - pGaps->m_from; if (pGaps->m_pNextGap) { const Gap *pGap = pGaps->m_pNextGap; do { nGapsSpace += pGap->m_to - pGap->m_from; pGap = pGap->m_pNextGap; } while (pGap); } const OdUInt32 dataSize = size(); OdFlatMetafileContainerWriter writer(pClone, dataSize - nGapsSpace, 1); const Gap *pGap = pGaps; OdUInt32 nCurPos = 0; do // Gaps is sorted anyway { const OdUInt32 nEndPos = (pGap) ? pGap->m_from : dataSize; if (nEndPos > nCurPos) writer.write(m_pData + nCurPos, nEndPos - nCurPos); nCurPos = (pGap) ? pGap->m_to : dataSize; if (pGap) pGap = pGap->m_pNextGap; } while (nCurPos < dataSize); return pClone; } // @@@TODO: implement effective paged memory container for metafile contents instead of flat container, which // can be unsafe on some platforms with big amount of data. /** \details Base paged memory container for metafile contents. */ /*class OdPagedMetafileContainer { struct Page { Page *m_pNextPage; OdUInt32 m_uPageLength; OdUInt8 *m_pData; }; Page *m_pPage; };*/ /** \details . Library: Source code provided. */ class OdBaseMetafileIOStream { protected: OdBaseMetafileContainerIOBase *m_pIO; public: /** \details Default constructor for the OdBaseMetafileIOStream class. */ OdBaseMetafileIOStream() : m_pIO(NULL) { } /** \details Constructor for the OdBaseMetafileIOStream class. Creates an instance from the specified IO metafile container. \param pIO [in] Pointer to IO metafile container. */ OdBaseMetafileIOStream(OdBaseMetafileContainerIOBase *pIO) : m_pIO(pIO) { } /** \details Sets a container for this object. \param pIO [in] Pointer to IO metafile container. */ virtual void setContainerIO(OdBaseMetafileContainerIOBase *pIO) { m_pIO = pIO; } /** \details Returns container associated with this object. \returns Pointer to IO metafile container associated with this object. */ virtual OdBaseMetafileContainerIOBase *containerIO() const { return m_pIO; } /** \details Returns size of entire allocated memory. \returns Allocated memory in bytes. */ virtual OdUInt32 size() const { return m_pIO->size(); } /** \details Returns current position in the container. \returns Position in memory. */ virtual OdUInt32 position() const { return m_pIO->position(); } /** \details Resets current position. \param delta [in] Move distance. \param forward [in] Flag that specifies seek direction. It true - seeks forward, if false - seeks backwards. */ virtual void seek(OdUInt32 delta, bool forward = true) { m_pIO->seek(delta, forward); } }; /** \details . Library: Source code provided. */ class OdBaseMetafileInputStream : public /*virtual*/ OdBaseMetafileIOStream { public: /** \details Default constructor for the OdBaseMetafileInputStream class. */ OdBaseMetafileInputStream() : OdBaseMetafileIOStream() { } /** \details Constructor for the OdBaseMetafileContainerIOBase class. Creates an instance from the specified metafile container. \param pIO [in] Pointer to base metafile container. */ OdBaseMetafileInputStream(OdBaseMetafileContainerIOBase *pIO) : OdBaseMetafileIOStream(pIO) { } /** \details Returns a container reader. \returns Pointer to a metafile reader. */ OdBaseMetafileContainerReader *containerReader() const { return static_cast(m_pIO); } // Binary level /** \details Returns pointer to the data in memory at current caret position. \returns Pointer to the data in memory. */ virtual const void *memoryPtr() const { return containerReader()->memoryPtr(); } /** \details Reads data from memory. \param data [out] Receives data. \param size [in] Size of the data array. */ virtual void read(void *data, OdUInt32 size) const { containerReader()->read(data, size); } /** \details Checks whether caret at the end of data. \returns true if caret is positioned at the end of file, false otherwise. */ virtual bool isEof() const { return containerReader()->isEof(); } // Read DD types #define READ_TYPE_DEF(type) \ type rVal; \ read(&rVal, sizeof(type)); \ return rVal /** \details Reads data of OdInt8 type (signed int 8 bits) from the memory. \returns Read OdInt8 value. */ OdInt8 readInt8() const { READ_TYPE_DEF(OdInt8); } /** \details Reads data of OdUInt8 type (unsigned int 8 bits) from the memory. \returns Read OdUInt8 value. */ OdUInt8 readUInt8() const { READ_TYPE_DEF(OdUInt8); } /** \details Reads data of OdInt16 type (signed int 16 bits) from the memory. \returns Read OdInt16 value. */ OdInt16 readInt16() const { READ_TYPE_DEF(OdInt16); } /** \details Reads data of OdUInt16 type (unsigned int 16 bits) from the memory. \returns Read OdUInt16 value. */ OdUInt16 readUInt16() const { READ_TYPE_DEF(OdUInt16); } /** \details Reads data of OdInt32 type (signed int 32 bits) from the memory. \returns Read OdInt32 value. */ OdInt32 readInt32() const { READ_TYPE_DEF(OdInt32); } /** \details Reads data of OdUInt32 type (unsigned int 32 bits) from the memory. \returns Read OdUInt32 value. */ OdUInt32 readUInt32() const { READ_TYPE_DEF(OdUInt32); } /** \details Reads data of OdInt64 type (signed int 64 bits) from the memory. \returns Read OdInt64 value. */ OdInt64 readInt64() const { READ_TYPE_DEF(OdInt64); } /** \details Reads data of OdUInt64 type (unsigned int 64 bits) from the memory. \returns Read OdUInt64 value. */ OdUInt64 readUInt64() const { READ_TYPE_DEF(OdUInt64); } /** \details Reads data of float type from the memory. \returns Read float value. */ float readFloat() const { READ_TYPE_DEF(float); } /** \details Reads data of double type from the memory. \returns Read double value. */ double readDouble() const { READ_TYPE_DEF(double); } /** \details Reads data of bool type from the memory. \returns Read bool value. */ bool readBool() const { READ_TYPE_DEF(bool); } /** \details Reads the entity color data from the memory. \returns Read OdCmEntityColor instance. */ OdCmEntityColor readCmEntityColor() const { READ_TYPE_DEF(OdCmEntityColor); } /** \details Reads data of OdGePoint2d type from the memory. \returns Read OdGePoint2d instance. */ OdGePoint2d readPoint2d() const { READ_TYPE_DEF(OdGePoint2d); } /** \details Reads data of OdGePoint3d type from the memory. \returns Read OdGePoint3d instance. */ OdGePoint3d readPoint3d() const { READ_TYPE_DEF(OdGePoint3d); } /** \details Reads data of OdGeVector2d type from the memory. \returns Read OdGeVector2d instance. */ OdGeVector2d readVector2d() const { READ_TYPE_DEF(OdGeVector2d); } /** \details Reads data of OdGeVector3d type from the memory. \returns Read OdGeVector3d instance. */ OdGeVector3d readVector3d() const { READ_TYPE_DEF(OdGeVector3d); } /** \details Reads data of OdGeQuaternion type from the memory. \returns Read OdGeQuaternion instance. */ OdGeQuaternion readQuaternion() const { READ_TYPE_DEF(OdGeQuaternion); } /** \details Reads data of OdGeMatrix2d type from the memory. \returns Read OdGeMatrix2d instance. */ OdGeMatrix2d readMatrix2d() const { READ_TYPE_DEF(OdGeMatrix2d); } /** \details Reads data of OdGeMatrix3d type from the memory. \returns Read OdGeMatrix3d instance. */ OdGeMatrix3d readMatrix3d() const { READ_TYPE_DEF(OdGeMatrix3d); } /** \details Reads the color data defined by the ODCOLORREF macro. \returns Color reference data represented by the ODCOLORREF macro. */ ODCOLORREF readColorRef() const { READ_TYPE_DEF(ODCOLORREF); } /** \details Reads a pointer from the memory. \returns Data represented by the pointer. */ void *readPointer() const { READ_TYPE_DEF(void*); } /** \details Reads a the GS marker data from the memory. \returns Read OdGsMarker value. */ OdGsMarker readGsMarker() const { READ_TYPE_DEF(OdGsMarker); } #undef READ_TYPE_DEF // Read DD arrays #define READ_ARRAY_DEF(type) \ read(pVal, nSize * sizeof(type)) /** \details Reads an array of OdInt8 values (signed int 8 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readInt8Array(OdInt8 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdInt8); } /** \details Reads an array of OdUInt8 values (unsigned int 8 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readUInt8Array(OdUInt8 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdUInt8); } /** \details Reads an array of OdInt16 values (signed int 16 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readInt16Array(OdInt16 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdInt16); } /** \details Reads an array of OdInt16 values (unsigned int 16 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readUInt16Array(OdUInt16 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdUInt16); } /** \details Reads an array of OdInt32 values (signed int 32 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readInt32Array(OdInt32 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdInt32); } /** \details Reads an array of OdUInt32 values (signed int 32 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readUInt32Array(OdUInt32 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdUInt32); } /** \details Reads an array of OdInt64 values (signed int 64 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readInt64Array(OdInt64 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdInt64); } /** \details Reads an array of OdUInt64 values (unsigned int 64 bits) from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readUInt64Array(OdUInt64 *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdUInt64); } /** \details Reads an array of float values from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readFloatArray(float *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(float); } /** \details Reads an array of double values from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readDoubleArray(double *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(double); } /** \details Reads an array of bool values from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readBoolArray(bool *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(bool); } /** \details Reads an array of OdCmEntityColor instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readCmEntityColorArray(OdCmEntityColor *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdCmEntityColor); } /** \details Reads an array of OdGePoint2d instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readPoint2dArray(OdGePoint2d *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGePoint2d); } /** \details Reads an array of OdGePoint3d instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readPoint3dArray(OdGePoint3d *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGePoint3d); } /** \details Reads an array of OdGeVector2d instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readVector2dArray(OdGeVector2d *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGeVector2d); } /** \details Reads an array of OdGeVector3d instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readVector3dArray(OdGeVector3d *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGeVector3d); } /** \details Reads an array of OdGeQuaternion instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readQuaternionArray(OdGeQuaternion *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGeQuaternion); } /** \details Reads an array of OdGeMatrix2d instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readMatrix2dArray(OdGeMatrix2d *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGeMatrix2d); } /** \details Reads an array of OdGeMatrix3d instances from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readMatrix3dArray(OdGeMatrix3d *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGeMatrix3d); } /** \details Reads an array of ODCOLORREF values from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readColorRefArray(ODCOLORREF *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(ODCOLORREF); } /** \details Reads an array of OdGsMarker values from the memory. \param pVal [out] Receives data. \param nSize [in] Size of the data array. */ void readGsMarkerArray(OdGsMarker *pVal, OdUInt32 nSize) const { READ_ARRAY_DEF(OdGsMarker); } #undef READ_ARRAY_DEF /** \details Reads a string from the memory. \returns Read string. */ OdString readString() const { OdString rStr; OdUInt32 uSize = readUInt32(); if (uSize) { OdCharArray chars; chars.resize(uSize + 1); chars.at(uSize) = 0; read(chars.asArrayPtr(), uSize * sizeof(OdChar)); rStr = chars.asArrayPtr(); } return rStr; } }; /** \details . Library: Source code provided. */ class OdBaseMetafileOutputStream : public /*virtual*/ OdBaseMetafileIOStream { public: /** \details Default constructor for the OdBaseMetafileOutputStream class. */ OdBaseMetafileOutputStream() : OdBaseMetafileIOStream() { } /** \details Constructor for the OdBaseMetafileOutputStream class. Creates an instance from the specified metafile container. \param pIO [in] Pointer to IO metafile container. */ OdBaseMetafileOutputStream(OdBaseMetafileContainerIOBase *pIO) : OdBaseMetafileIOStream(pIO) { } /** \details Returns a container writer. \returns Pointer to a metafile writer. */ OdBaseMetafileContainerWriter *containerWriter() const { return static_cast(m_pIO); } // Binary level /** \details Reserves memory for write operation. \param size [in] Memory size to reserve. \param moveCaret [in] Flag that specifies whether to change current caret position. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ virtual void reserve(OdUInt32 size, bool moveCaret = true, bool lockPage = true) { containerWriter()->reserve(size, moveCaret, lockPage); } /** \details Write data to memory. \param data [in] Pointer to an array of data to write. \param size [in] Size of the data array. \param lockPage [in] Flag that specifies whether to lock page in physical memory. */ virtual void write(const void *data, OdUInt32 size, bool lockPage = true) { containerWriter()->write(data, size, lockPage); } /** \details Truncates allocations to use optimal memory size. \remarks Call after all writing operations are completed. */ virtual void completeWriting() { containerWriter()->completeWriting(); } // Write DD types #define WRITE_TYPE_DEF(type) \ write(&value, sizeof(type)) /** \details Writes data of OdInt8 type (signed int 8 bits) into the memory. \param value [in] Data to write. */ void writeInt8(OdInt8 value) { WRITE_TYPE_DEF(OdInt8); } /** \details Writes data of OdUInt8 type (unsigned int 8 bits) into the memory. \param value [in] Data to write. */ void writeUInt8(OdUInt8 value) { WRITE_TYPE_DEF(OdUInt8); } /** \details Writes data of OdInt16 type (signed int 16 bits) into the memory. \param value [in] Data to write. */ void writeInt16(OdInt16 value) { WRITE_TYPE_DEF(OdInt16); } /** \details Writes data of OdUInt16 type (unsigned int 16 bits) into the memory. \param value [in] Data to write. */ void writeUInt16(OdUInt16 value) { WRITE_TYPE_DEF(OdUInt16); } /** \details Writes data of OdInt32 type (signed int 32 bits) into the memory. \param value [in] Data to write. */ void writeInt32(OdInt32 value) { WRITE_TYPE_DEF(OdInt32); } /** \details Writes data of OdUInt32 type (unsigned int 32 bits) into the memory. \param value [in] Data to write. */ void writeUInt32(OdUInt32 value) { WRITE_TYPE_DEF(OdUInt32); } /** \details Writes data of OdInt64 type (signed int 64 bits) into the memory. \param value [in] Data to write. */ void writeInt64(OdInt64 value) { WRITE_TYPE_DEF(OdInt64); } /** \details Writes data of OdUInt64 type (unsigned int 64 bits) into the memory. \param value [in] Data to write. */ void writeUInt64(OdUInt64 value) { WRITE_TYPE_DEF(OdUInt64); } /** \details Writes data of float type into the memory. \param value [in] Data to write. */ void writeFloat(float value) { WRITE_TYPE_DEF(float); } /** \details Writes data of double type into the memory. \param value [in] Data to write. */ void writeDouble(double value) { WRITE_TYPE_DEF(double); } /** \details Writes data of bool type into the memory. \param value [in] Data to write. */ void writeBool(bool value) { WRITE_TYPE_DEF(bool); } /** \details Writes data of OdCmEntityColor type into the memory. \param value [in] Data to write. */ void writeCmEntityColor(const OdCmEntityColor &value) { WRITE_TYPE_DEF(OdCmEntityColor); } /** \details Writes data of OdGePoint2d type into the memory. \param value [in] Data to write. */ void writePoint2d(const OdGePoint2d &value) { WRITE_TYPE_DEF(OdGePoint2d); } /** \details Writes data of OdGePoint3d type into the memory. \param value [in] Data to write. */ void writePoint3d(const OdGePoint3d &value) { WRITE_TYPE_DEF(OdGePoint3d); } /** \details Writes data of OdGeVector2d type into the memory. \param value [in] Data to write. */ void writeVector2d(const OdGeVector2d &value) { WRITE_TYPE_DEF(OdGeVector2d); } /** \details Writes data of OdGeVector3d type into the memory. \param value [in] Data to write. */ void writeVector3d(const OdGeVector3d &value) { WRITE_TYPE_DEF(OdGeVector3d); } /** \details Writes data of OdGeQuaternion type into the memory. \param value [in] Data to write. */ void writeQuaternion(const OdGeQuaternion &value) { WRITE_TYPE_DEF(OdGeQuaternion); } /** \details Writes data of OdGeMatrix2d type into the memory. \param value [in] Data to write. */ void writeMatrix2d(const OdGeMatrix2d &value) { WRITE_TYPE_DEF(OdGeMatrix2d); } /** \details Writes data of OdGeMatrix3d type into the memory. \param value [in] Data to write. */ void writeMatrix3d(const OdGeMatrix3d &value) { WRITE_TYPE_DEF(OdGeMatrix3d); } /** \details Writes data of ODCOLORREF type into the memory. \param value [in] Data to write. */ void writeColorRef(ODCOLORREF value) { WRITE_TYPE_DEF(ODCOLORREF); } /** \details Writes data represented by a pointer into the memory. \param value [in] Data to write. */ void writePointer(const void *value) { WRITE_TYPE_DEF(void*); } /** \details Writes data of OdGsMarker type into the memory. \param value [in] Data to write. */ void writeGsMarker(OdGsMarker value) { WRITE_TYPE_DEF(OdGsMarker); } #undef WRITE_TYPE_DEF // Write DD arrays #define WRITE_ARRAY_DEF(type) \ write(pVal, nSize * sizeof(type)) /** \details Writes an array of OdInt8 values (signed int 8 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeInt8Array(const OdInt8 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdInt8); } /** \details Writes an array of OdUInt8 values (unsigned int 8 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeUInt8Array(const OdUInt8 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdUInt8); } /** \details Writes an array of OdInt16 values (signed int 16 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeInt16Array(const OdInt16 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdInt16); } /** \details Writes an array of OdInt16 values (unsigned int 16 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeUInt16Array(const OdUInt16 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdUInt16); } /** \details Writes an array of OdInt32 values (signed int 32 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeInt32Array(const OdInt32 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdInt32); } /** \details Writes an array of OdUInt32 values (signed int 32 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeUInt32Array(const OdUInt32 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdUInt32); } /** \details Writes an array of OdInt64 values (signed int 64 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeInt64Array(const OdInt64 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdInt64); } /** \details Writes an array of OdUInt64 values (unsigned int 64 bits) into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeUInt64Array(const OdUInt64 *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdUInt64); } /** \details Writes an array of float values into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeFloatArray(const float *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(float); } /** \details Writes an array of double values into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeDoubleArray(const double *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(double); } /** \details Writes an array of bool values into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeBoolArray(const bool *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(bool); } /** \details Writes an array of OdCmEntityColor instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeCmEntityColorArray(const OdCmEntityColor *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdCmEntityColor); } /** \details Writes an array of OdGePoint2d instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writePoint2dArray(const OdGePoint2d *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGePoint2d); } /** \details Writes an array of OdGePoint3d instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writePoint3dArray(const OdGePoint3d *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGePoint3d); } /** \details Writes an array of OdGeVector2d instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeVector2dArray(const OdGeVector2d *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGeVector2d); } /** \details Writes an array of OdGeVector3d instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeVector3dArray(const OdGeVector3d *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGeVector3d); } /** \details Writes an array of OdGeQuaternion instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeQuaternionArray(const OdGeQuaternion *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGeQuaternion); } /** \details Writes an array of OdGeMatrix2d instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeMatrix2dArray(const OdGeMatrix2d *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGeMatrix2d); } /** \details Writes an array of OdGeMatrix3d instances into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeMatrix3dArray(const OdGeMatrix3d *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGeMatrix3d); } /** \details Writes an array of ODCOLORREF values into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeColorRefArray(const ODCOLORREF *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(ODCOLORREF); } /** \details Writes an array of OdGsMarker values into the memory. \param pVal [in] Data to write. \param nSize [in] Size of the data array. */ void writeGsMarkerArray(const OdGsMarker *pVal, OdUInt32 nSize) { WRITE_ARRAY_DEF(OdGsMarker); } #undef WRITE_ARRAY_DEF /** \details Writes a string into the memory. \param pChars [in] Pointer to an array of characters. \param nChars [in] Size of the data array. */ void writeString(const OdChar *pChars, OdUInt32 nChars) { writeUInt32(nChars); if (nChars) write(pChars, nChars * sizeof(OdChar)); } /** \details Writes a string into the memory. \param str [in] Data to write. */ void writeString(const OdString &str) { writeString(str.c_str(), (OdUInt32)str.getLength()); } }; #include "TD_PackPop.h" #endif // _METAFILESTREAMBASE_INCLUDED_