opennurbs_archive.h
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #if !defined(ON_ARCHIVE_INC_)
00018 #define ON_ARCHIVE_INC_
00019 
00020 class ON_CLASS ON_FileStream
00021 {
00022 public:
00023   /*
00024   Description:
00025     Portable wrapper for C runtime fopen().
00026   Parameters:
00027     filename - [in]
00028     mode - [in]
00029   Remarks:
00030     Use the ON_FileStream static functions for reading, writing, 
00031     seeking, position finding with the FILE pointer returned
00032     by this function.
00033   */
00034   static FILE* Open( const wchar_t* filename, const wchar_t* mode );
00035 
00036   /*
00037   Description:
00038     Portable wrapper for C runtime fopen().
00039   Parameters:
00040     filename - [in]
00041     mode - [in]
00042   Remarks:
00043     Use the ON_FileStream static functions for reading, writing, 
00044     seeking, position finding with the FILE pointer returned
00045     by this function.
00046   */
00047   static FILE* Open( const char* filename, const char* mode );
00048   
00049   /*
00050   Description:
00051     Portable wrapper for C runtime fclose().
00052   Parameters:
00053     fp - [in]
00054       FILE pointer returned by ON_FileStream::Open().
00055   Returns:
00056        0: successful
00057       -1: null fp parameter
00058     != 0: fclose() failure code
00059   */
00060   static int Close( FILE* fp );
00061 
00062   /*
00063   Description:
00064     Portable wrapper for C runtime ftell().
00065   Parameters:
00066     fp - [in]
00067       FILE pointer returned by ON_FileStream::Open().
00068   Returns:
00069     >= 0: current file position
00070       -1: an error occured
00071   */
00072   static ON__INT64 CurrentPosition( FILE* fp );
00073 
00074   /*
00075   Description:
00076     Portable wrapper for C runtime fseek(fp,offset,SEEK_CUR).
00077   Parameters:
00078     fp - [in]
00079       FILE pointer returned by ON_FileStream::Open().
00080     offset - [in]
00081   */
00082   static bool SeekFromCurrentPosition( FILE* fp, ON__INT64 offset );
00083 
00084   /*
00085   Description:
00086     Portable wrapper for C runtime fseek(fp,offset,SEEK_SET).
00087   Parameters:
00088     fp - [in]
00089       FILE pointer returned by ON_FileStream::Open().
00090     offset - [in]
00091   */
00092   static bool SeekFromStart( FILE* fp, ON__INT64 offset );
00093 
00094   /*
00095   Description:
00096     Portable wrapper for C runtime fseek(fp,offset,SEEK_END).
00097   Parameters:
00098     fp - [in]
00099       FILE pointer returned by ON_FileStream::Open().
00100     offset - [in]
00101   */
00102   static bool SeekFromEnd( FILE* fp, ON__INT64 offset );
00103 
00104   /*
00105   Description:
00106     Portable wrapper for C runtime fseek(fp,offset,origin).
00107   Parameters:
00108     fp - [in]
00109       FILE pointer returned by ON_FileStream::Open().
00110     offset - [in]
00111     origin - [in]
00112       SEEK_SET (0): seek from beginning of file.  
00113       SEEK_CUR (1): seek from current position of file pointer.
00114       SEEK_END (2): seek from end of file.
00115   */
00116   static bool Seek( FILE* fp, ON__INT64 offset, int orgin );
00117 
00118   /*
00119   Description:
00120     Portable wrapper for C runtime fread(buffer,1,count,fp).
00121   Parameters:
00122     fp - [in]
00123       FILE pointer returned by ON_FileStream::Open()
00124     count - [in]
00125       number of bytes to read.
00126     buffer - [out]
00127       read bytes are stored in this buffer
00128   Returns:
00129     number of bytes read
00130   */
00131   static ON__UINT64 Read( FILE* fp, ON__UINT64 count, void* buffer );
00132 
00133   /*
00134   Description:
00135     Portable wrapper for C runtime fwrite(buffer,1,count,fp).
00136   Parameters:
00137     fp - [in]
00138       FILE pointer returned by ON_FileStream::Open()
00139     count - [in]
00140       number of bytes to write
00141     buffer - [in]
00142       data to be written
00143   Returns:
00144     number of bytes written.
00145   */
00146   static ON__UINT64 Write( FILE* fp, ON__UINT64 count, const void* buffer );
00147 
00148   /*
00149   Description:
00150     Portable wrapper for C runtime fflush(fp).
00151   Parameters:
00152     fp - [in]
00153       FILE pointer returned by ON_FileStream::Open().
00154   Returns:
00155     true if flush was successful.  False if an error occured.
00156   */
00157   static bool Flush( FILE* fp );
00158 
00159   /*
00160   Description:
00161     Portable wrapper for C runtime fstat().
00162   Parameters:
00163     fp - [in]
00164       FILE pointer returned by ON_FileStream::Open().
00165     file_size - [out]
00166       If file_size is not null, the the size of the file
00167       in bytes returned here
00168     file_creation_time - [out]
00169       If file_creation_time is not null, then the time the file 
00170       was created is returned here as the number of seconds since
00171       midnight January 1, 1970.
00172     file_last_modified_time - [out]
00173       If file_last_modified_time is not null, then the time the file
00174       was last modified is returned here as the number of seconds
00175       since midnight January 1, 1970.
00176   Returns:
00177     true if the query was successful.  False if an error occured.
00178   */
00179   static bool GetFileInformation( 
00180     FILE* fp,
00181     ON__UINT64* file_size,
00182     ON__UINT64* file_create_time,
00183     ON__UINT64* file_last_modified_time
00184     );
00185 };
00186 
00187 class ON_CLASS ON_FileIterator
00188 {
00189 public:
00190   ON_FileIterator();
00191   ~ON_FileIterator();
00192   void Destroy();
00193 
00194   /*
00195   Description:
00196     Find the first matching file in the directory.
00197   Parameters:
00198     directory_name - [in]
00199       The directory to look in.
00200     file_name_filter - [in]
00201       If this paramter is null, then the iteration
00202       includes all names in the directory.
00203       The file name to search for. This parameter can 
00204       include wildcard characters, such as an
00205       asterisk (*) or a question mark (?). For example,
00206       "\rootdir\subdir\*.*"  will iterate all files in
00207       the \rootdir\subdir\ directory.
00208 
00209   Example:
00210           // Iterate through the files in a directory named "\rootdir\subdir"
00211           FILE* fp = 0;
00212           ON_FileIterator fit;
00213           const char* directory = "\\rootdir\\subdir";
00214           for ( const wchar_t* filename = fit.FirstFile( directory, "*.3dm" );
00215                 0 != filename;
00216                 filename = fit.NextFile()
00217               )
00218           {
00219             if ( fit.CurrentFileIsDirectory() )
00220               continue;
00221             ON_String fullpath = directory;
00222             fullpath += '\\';
00223             fullpath += filename;
00224             FILE* fp = ON_FileStream::Open(fullpath,"rb");
00225             if ( 0 == fp )
00226             {
00227               continue;
00228             }
00229             ...
00230             ON_FileStream::Close(fp);
00231             fp = 0;
00232           }
00233         }
00234 
00235   Returns:
00236     NULL if no matching files are present in the directory.
00237   */
00238   const wchar_t* FirstFile( 
00239     const wchar_t* directory_name, 
00240     const wchar_t* file_name_filter
00241     );
00242 
00243   const wchar_t* FirstFile( 
00244     const char* directory_name, 
00245     const char* file_name_filter
00246     );
00247 
00248   /*
00249   Description:
00250     Find the next matching file in the directory.
00251   Returns:
00252     NULL if no more matching files are present in the directory.
00253   */
00254   const wchar_t* NextFile();
00255 
00256   const wchar_t* CurrentFileName() const;
00257 
00258   ON__UINT64 CurrentFileSize() const;
00259 
00260   /*
00261   Returns 
00262     true if the current "file" is a directory.
00263   */
00264   bool CurrentFileIsDirectory() const;
00265 
00266   /*
00267   Returns 
00268     true if the current file or directory is hidden.
00269     This means its name begins with a '.' or it's
00270     Windows hidden attribute is true.
00271   */
00272   bool CurrentFileIsHidden() const;
00273 
00274   bool GetCurrentFullPathFileName( ON_wString& filename ) const;
00275 
00276   /*
00277   Returns:
00278     File creation time in seconds since January 1, 1970
00279   */
00280   ON__UINT64 CurrentFileCreateTime() const;
00281 
00282   /*
00283   Returns:
00284     File last modified time in seconds since January 1, 1970
00285   */
00286   ON__UINT64 CurrentFileLastModifiedTime() const;
00287 
00288   /*
00289   Returns:
00290     File last access time in seconds since January 1, 1970
00291   */
00292   ON__UINT64 CurrentFileLastAccessTime() const;
00293 
00294   /*
00295   Returns:
00296     Number of matching files returned so far.
00297   */
00298   ON__UINT64 Count() const;
00299 
00300 private:
00301   // Used by Windows ::Find
00302   ON__UINT64 m_count;
00303   ON_wString m_directory;
00304 
00305 #if defined(ON_COMPILER_MSC)
00306   ON__UINT32 m_file_attributes_mask;
00307   HANDLE m_h;
00308   WIN32_FIND_DATA m_fd;
00309 #else
00310   ON_wString m_ws_file_name_filter;
00311   ON_String m_utf8_file_name_filter;
00312   DIR* m_dir;
00313   struct dirent m_dirent;
00314   char m_dirent_name_buffer[NAME_MAX+1]; // < this field provide storage for m_dirent.d_name[]
00315 
00316   // information about the current file
00317   wchar_t m_current_name[1024];
00318   ON__UINT64 m_current_file_attributes; // 1 = regular file, 2 = directory
00319   ON__UINT64 m_current_file_size;
00320   ON__UINT64 m_current_file_create_time;
00321   ON__UINT64 m_current_last_modified_time;
00322   ON__UINT64 m_current_last_access_time;
00323 #endif
00324 };
00325 
00326 
00328 //
00329 // ON_Buffer 
00330 //
00331 
00332 typedef void (*ON_Buffer_ErrorHandler)(class ON_Buffer*);
00333 
00334 class ON_CLASS ON_Buffer
00335 {
00336 public:
00337   ON_Buffer();
00338   ~ON_Buffer();
00339 
00340   ON_Buffer(const ON_Buffer& src);
00341   ON_Buffer& operator=(const ON_Buffer& src);
00342 
00343   /*
00344   Description:
00345     Compare contents of buffers.
00346   Paramters:
00347     a - [in]
00348     b - [in]
00349   Returns:
00350     -1: a < b
00351      0: a == b
00352      1: a > b
00353   */
00354   static int Compare( const ON_Buffer& a, const ON_Buffer& b );
00355 
00356   void Destroy();
00357   void EmergencyDestroy();
00358 
00359   /*
00360   Returns:
00361     True if Size() == CurrentPosition().
00362   Remarks:
00363     It is possible to seek beyond the end of the buffer.
00364     In this case, the current position will be past the end
00365     of the buffer and AtEnd() will return false.
00366   */
00367   bool AtEnd() const;
00368 
00369   /*
00370   Returns:
00371     Number of bytes currently in the buffer.
00372   Remarks:
00373     It is possible to seek beyond the end of the buffer.
00374     In this case, the current position will be past the end
00375     of the buffer and CurrentPosition() will be greater than
00376     Size().
00377   */
00378   ON__UINT64 Size() const;
00379 
00380   /*
00381   Returns:
00382     32-bit CRC of the buffer contents.
00383   Remarks:
00384     
00385   */
00386   ON__UINT32 CRC32( ON__UINT32 current_remainder ) const;
00387 
00388 
00389   /*
00390   Returns:
00391     Current position in the buffer.
00392   Remarks:
00393     It is possible to seek beyond the end of the buffer.
00394     In this case, the current position will be past the end
00395     of the buffer and CurrentPosition() will be greater than
00396     Size().
00397   */
00398   ON__UINT64 CurrentPosition() const;
00399   
00400   /*
00401   Parameters:
00402     size - [in]
00403       number of bytes to write.
00404     buffer - [in]
00405       values to write.
00406   Returns:
00407     Number of bytes written buffer.
00408   */
00409   ON__UINT64 Write( ON__UINT64 size, const void* buffer );
00410 
00411   /*
00412   Parameters:
00413     size - [in]
00414       number of bytes to read.
00415     buffer - [out]
00416       read values are returned in buffer.
00417   Returns:
00418     Number of bytes read into buffer. For example, 
00419     if CurrentPosition() <= Size() and 
00420     size > (Size() - CurrentPosition()) and
00421     buffer is not null, then the value
00422     (Size() - CurrentPosition()) is returned.
00423   Remarks:
00424     If the size parameter is zero, then nothing is done.
00425     When CurrentPosition() <= Size(), attempts to read more 
00426     than (Size() - CurrentPosition()) bytes do not generate 
00427     an error. When CurrentPosition() > Size(), any attempt
00428     to read generates an error.
00429   */
00430   ON__UINT64 Read( ON__UINT64 size, void* buffer );
00431 
00432   enum
00433   {
00434     seek_from_beginning_of_file = 0,
00435     seek_from_current_position = 1,
00436     seek_from_end_of_file = 2
00437   };
00438 
00439   /*
00440   Parameters:
00441     offset - [in]
00442       number of bytes to seek from origin
00443     origin - [in]
00444       initial position.
00445         0 (SEEK_SET) Seek from beginning of file.
00446         1 (SEEK_CUR) Seek from current position.
00447         2 (SEEK_END) Seek from end of file.
00448   Returns:
00449     True if successful.
00450     False if the seek would result in a file position
00451     before the beginning of the file. If false is
00452     returned, the current position is not changed.
00453   Remarks:
00454     Seeking beyond the end of the buffer is succeeds.
00455     Seeking before the beginning of the buffer fails.
00456   */
00457   bool Seek( 
00458     ON__INT64 offset, 
00459     int origin 
00460     );
00461 
00462   /*
00463   Parameters:
00464     offset - [in] (>= 0)
00465       number of bytes to seek from the start of the buffer.
00466   Returns:
00467     True if successful.
00468     False if the seek would result in a file position
00469     before the beginning of the file. If false is
00470     returned, the current position is not changed.
00471   Remarks:
00472     Seeking beyond the end of the buffer is succeeds.
00473     Seeking before the beginning of the buffer fails.
00474   */
00475   bool SeekFromStart( ON__INT64 offset ); 
00476 
00477   /*
00478   Parameters:
00479     offset - [in]
00480       number of bytes to seek from the current position.
00481   Returns:
00482     True if successful.
00483     False if the seek would result in a file position
00484     before the beginning of the file. If false is
00485     returned, the current position is not changed.
00486   Remarks:
00487     Seeking beyond the end of the buffer is succeeds.
00488     Seeking before the beginning of the buffer fails.
00489   */
00490   bool SeekFromCurrentPosition( ON__INT64 offset ); 
00491 
00492   /*
00493   Parameters:
00494     offset - [in]
00495       number of bytes to seek from the end fo the buffer.
00496   Returns:
00497     True if successful.
00498     False if the seek would result in a file position
00499     before the beginning of the file. If false is
00500     returned, the current position is not changed.
00501   Remarks:
00502     Seeking beyond the end of the buffer is succeeds.
00503     Seeking before the beginning of the buffer fails.
00504   */
00505   bool SeekFromEnd( ON__INT64 offset ); 
00506 
00507   /*
00508   Parameters:
00509     buffer_size - [in]
00510       new size of buffer.
00511   Returns:
00512     True if successful.    
00513   Remarks:
00514     The current position is not changed and may be beyond the
00515     end of the file. Use Seek to set the current position after
00516     calling ChangeSize().
00517   */
00518   bool ChangeSize( ON__UINT64 buffer_size );
00519 
00520   /*
00521   Description:
00522     Return unused memory to heap.
00523   Remarks:
00524     Call this function after creating an ON_Buffer that will persist for
00525     and extended amount of time. There are never more than 16 pages of
00526     unsued memory (16*4096 bytes on most computers) in an ON_Buffer.
00527     Compact() can be called at any time, but calling Compact() the then
00528     writing at the end of the buffer is not an efficient use of time
00529     or memory.
00530   */
00531   bool Compact();
00532 
00533   /*
00534   Returns
00535     True if the ON_Buffer is valid.
00536   */
00537   bool IsValid( const ON_TextLog* text_log ) const;
00538 
00539   /*
00540   Returns:
00541     Value that identifies most recent error.
00542     0: no error
00543     1: attempt to seek to a negative position
00544   */
00545   ON__UINT32 LastError() const;
00546   
00547   void ClearLastError();
00548 
00549   ON_Buffer_ErrorHandler ErrorHandler() const;
00550   
00551   void SetErrorHandler(ON_Buffer_ErrorHandler error_handler);
00552 
00553   /*
00554   Description:
00555     Use WriteToBinaryArchive() to save an entire ON_Buffer inside
00556     a binary archive.  Use ReadFromBinaryArchive() to retrieve
00557     the ON_Buffer from the ON_BinaryArchive.
00558   */
00559   bool WriteToBinaryArchive( ON_BinaryArchive& ) const;
00560 
00561   /*
00562   Description:
00563     Use ReadFromBinaryArchive() to retrieve an entire ON_Buffer
00564     that was written using WriteToBinaryArchive().
00565   */
00566   bool ReadFromBinaryArchive( ON_BinaryArchive& );
00567 
00568   /*
00569   Description:
00570     Compress this buffer
00571 
00572   Parameters:
00573     compressed_buffer - [out]
00574       (The reference can be *this)
00575   
00576   Example:
00577 
00578         // compress a buffer in place
00579         ON_Buffer buffer;
00580         buffer = ...;
00581         if ( !buffer.Compress(buffer) )
00582         {
00583            // compression failed
00584         }
00585         else
00586         {
00587            // buffer is now compressed
00588         }
00589 
00590   Returns:
00591     True if successful.  False if failed.
00592   */
00593   bool Compress( ON_Buffer& compressed_buffer ) const;
00594 
00595   /*
00596   Description:
00597     Uncompress this buffer which must have been compressed using
00598     ON_Buffer::Compress().
00599 
00600   Parameters:
00601     uncompressed_buffer - [out]
00602       (The reference can be *this)
00603 
00604   Example:
00605         // silly example that compresses and then uncompresses a buffer in place
00606         // to show how to call the functions.
00607         ON_Buffer buffer;
00608         buffer = ...; // buffer is in it uncompressed form
00609         if ( buffer.Compress(buffer) )
00610         {
00611            // buffer is now compressed
00612            if ( buffer.Uncompress(buffer) )
00613            {
00614               // buffer is uncompressed again.
00615            }
00616         }
00617 
00618   Returns:
00619     True if successful.  False if failed.
00620   */
00621   bool Uncompress( ON_Buffer& uncompressed_buffer ) const;
00622 
00623 private:
00624 
00625   ON__UINT64 m_buffer_size; // total number of bytes in the buffer
00626   ON__UINT64 m_current_position;
00627 
00628   struct ON_BUFFER_SEGMENT* m_first_segment;
00629   struct ON_BUFFER_SEGMENT* m_last_segment;
00630   struct ON_BUFFER_SEGMENT* m_current_segment;
00631   bool SetCurrentSegment(bool);
00632   void Copy( const ON_Buffer& );
00633 
00634   ON_MEMORY_POOL* m_heap;
00635   ON_Buffer_ErrorHandler m_error_handler;
00636 
00637   ON__UINT32 m_last_error;
00638   unsigned char m_reserved[12];
00639 };
00640 
00642 //
00643 // ON_BinaryArchive 
00644 //      virtual class for CPU independent serialization
00645 //
00646 // ON_BinaryFile
00647 //      simple class for CPU independent binary file I/O
00648 //      includes optional CRC support
00649 //
00650 
00651 class ON_Object;
00652 class ON_Group;
00653 class ON_Font;
00654 class ON_DimStyle;
00655 class ON_Arc;
00656 class ON_ObjectAttributes;
00657 class ON_InstanceDefinition;
00658 class ON_HatchPattern;
00659 class ON_Linetype;
00660 
00661 struct ON_3DM_CHUNK
00662 {
00663   size_t m_offset; // In read or write_using_fseek mode, this is the
00664                    // file position of first byte after chunk's length.
00665                    // In write_using_buffer mode, this of the m_buffer[]
00666                    // position of first byte after chunk's length.
00667   unsigned int m_typecode;
00668   int m_value;
00669   int m_do_length; // true if chunk is a long chunk with length
00670   ON__UINT16 m_do_crc16; // 16 bit CRC using CCITT polynomial
00671   ON__UINT16 m_crc16;
00672   ON__UINT32 m_do_crc32; // 32 bit CRC
00673   ON__UINT32 m_crc32;
00674 };
00675 
00676 struct ON_3DM_BIG_CHUNK
00677 {
00678   ON__UINT64 m_big_offset; // In read or write_using_fseek mode, this is the
00679                            // file position of first byte after chunk's length.
00680                            // In write_using_buffer mode, this of the m_buffer[]
00681                            // position of first byte after chunk's length.
00682 
00683   ON__UINT64 Length() const; // 0 for short chunks
00684 
00685   ON__INT64 m_big_value;
00686   ON__UINT32 m_typecode;
00687 
00688   ON__UINT8 m_bLongChunk; // true if chunk is a long chunk and m_big_value is a length.
00689   ON__UINT8 m_reserved1;
00690   ON__UINT8 m_reserved2;
00691   ON__UINT8 m_reserved3;
00692 
00693   // CRC settings
00694   ON__UINT8 m_do_crc16; // true (1) if we are calculating 16 bit CRC
00695   ON__UINT8 m_do_crc32; // true (1) if we are calculating 32 bit CRC
00696   ON__UINT16 m_crc16; // current 16 bit CRC value
00697   ON__UINT32 m_crc32; // current 32 bit CRC value
00698 };
00699 
00700 bool ON_IsLongChunkTypecode(ON__UINT32 typecode);
00701 
00702 bool ON_IsShortChunkTypecode(ON__UINT32 typecode);
00703 
00704 #if defined(ON_DLL_TEMPLATE)
00705 // This stuff is here because of a limitation in the way Microsoft
00706 // handles templates and DLLs.  See Microsoft's knowledge base 
00707 // article ID Q168958 for details.
00708 #pragma warning( push )
00709 #pragma warning( disable : 4231 )
00710 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_3DM_CHUNK>;
00711 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_3DM_BIG_CHUNK>;
00712 #pragma warning( pop )
00713 #endif
00714 
00715 class ON_Light;
00716 class ON_Bitmap;
00717 class ON_TextureMapping;
00718 class ON_Material;
00719 class ON_Layer;
00720 class ON_3dmProperties;
00721 class ON_3dmSettings;
00722 class ON_3dmObjectAttributes;
00723 class ON_3dmGoo;
00724 
00725 class ON_BinaryArchive;
00726 
00727 // Used int ON_3dmProperties::Read() to set ON_BinaryArchive.m_3dm_opennurbs_version
00728 // Do not call directly. 
00729 void ON_SetBinaryArchiveOpenNURBSVersion(ON_BinaryArchive&,int);
00730 
00731 class ON_CLASS ON_BinaryArchive // use for generic serialization of binary data
00732 {
00733 public:
00734   ON_BinaryArchive( ON::archive_mode );
00735   virtual ~ON_BinaryArchive();
00736 
00737   virtual 
00738   size_t CurrentPosition( // current offset (in bytes) into archive ( like ftell() )
00739                 ) const = 0; 
00740   virtual 
00741   bool SeekFromCurrentPosition( // seek from current position ( like fseek( ,SEEK_CUR) )
00742                 int // byte offset ( >= -CurrentPostion() )
00743                 ) = 0; 
00744   virtual 
00745   bool SeekFromStart(  // seek from current position ( like fseek( ,SEEK_SET) )
00746                 size_t // byte offset ( >= 0 )
00747                 ) = 0;
00748   virtual 
00749   bool AtEnd() const = 0; // true if at end of file
00750 
00751   bool BigSeekFromStart( ON__UINT64 offset );
00752   bool BigSeekForward( ON__UINT64 offset );
00753   bool BigSeekBackward( ON__UINT64 offset );
00754   bool BigSeekFromCurrentPosition( ON__INT64 offset );
00755 
00756   /*
00757   Description:
00758     Tool for swapping bytes when doing I/O on
00759     using big endian CPUs.
00760   Remarks:
00761     3dm files are always saved with little endian byte order.
00762   See Also:
00763     ON_BinaryArchive::Endian
00764   */
00765   static
00766   bool ToggleByteOrder(
00767     int, // number of elements
00768     int, // size of element (2,4, or 8)
00769     const void*,  // source buffer
00770     void*         // destination buffer (can be same a source buffer)
00771     );
00772 
00773   static
00774   const char* TypecodeName( unsigned int tcode );
00775 
00776   static
00777   char* ON_TypecodeParse( unsigned int tcode, char* typecode_name, size_t max_length );
00778 
00779   bool ReadMode() const;  // true if reading is permitted
00780   bool WriteMode() const; // true if writing is permitted
00781   
00782   /*
00783   Returns:
00784      Endian-ness of the cpu reading this file.
00785   Remarks:
00786     3dm files are alwasy saved with little endian byte order.
00787   */
00788   ON::endian Endian() const; // endian-ness of cpu
00789 
00790   int BadCRCCount() const; // number of chunks read with bad CRC 
00791 
00792   bool ReadByte( size_t, void* ); // must fail if mode is not read or readwrite
00793 
00794   bool WriteByte( size_t, const void* ); // must fail if mode is not write or readwrite
00795 
00796   /*
00797   Description:
00798     Expert user function that uses Read() to load a buffer.
00799   Paramters:
00800     sizeof_buffer - [in] number of bytes to attempt to read.
00801     buffer - [out] read bytes are stored in this buffer
00802   Returns:
00803     Number of bytes actually read, which may be less than
00804     sizeof_buffer if the end of file is encountered.
00805   */
00806   ON__UINT64 ReadBuffer( ON__UINT64 sizeof_buffer, void* buffer );
00807 
00808   /*
00809   Description:
00810     Expert user function to control CRC calculation while reading and writing.
00811     Typically this is used when seeking around and reading/writing information
00812     in non-serial order.
00813   Parameters:
00814     bEnable  - [in]
00815   Returns:
00816     Current state of CRC calculation.  Use the returned value to restore the
00817     CRC calculation setting after you are finished doing your fancy pants
00818     expert IO.
00819   */
00820   bool EnableCRCCalculation( bool bEnable );
00821 
00822   // ReadCompressedBuffer()/WriteCompressedBuffer() use zlib 1.1.3
00823   // to inflate/deflate the data buffer.
00824   // Care must be used to get an endian independent file.  
00825   // See ON_Mesh::Read()/ON_Mesh::Write() for an example of an endian
00826   // independent use of compression. See also ToggleByteOrder() and Endian().
00827   //
00828   // To read data archived by WriteCompressedBuffer( sizeof_buffer, buffer )
00829   // do something like:
00830   //
00831   //   size_t sizeof_buffer = 0;
00832   //   ReadCompressedBufferSize(&sizeof_buffer);
00833   //   buffer = something with sizeof_buffer bytes.
00834   //   int bFailedCRC = false;
00835   //   bool ok = ReadCompressedBuffer( sizeof_buffer, buffer, &bFailedCRC );
00836   //
00837 
00838 
00839   /*
00840   Description:
00841     Red the size of a compressed buffer.
00842   Parameters:
00843     sizeof__outbuffer - [out] size of the uncompressed buffer in bytes
00844   Returns:
00845     True if read was successful.
00846   */
00847   bool ReadCompressedBufferSize( size_t* sizeof__outbuffer );
00848 
00849   /*
00850   Description:
00851     Read compressed information from an archive and uncompress it.
00852   Parameters:
00853     sizeof__outbuffer - [in] size of the uncompressed buffer in bytes
00854     outbuffer - [out] uncompressed buffer returned here
00855     bFailedCRC - [out] true if cyclic redundancy check fails
00856                       on uncompressed buffer
00857 
00858   Example:
00859 
00860           size_t sizeof_buffer = 0;
00861           ReadCompressedBufferSize(&sizeof_buffer);
00862           buffer = ...; // something with sizeof_buffer bytes.
00863           int bFailedCRC = false;
00864           bool ok = ReadCompressedBuffer( sizeof_buffer, buffer, &bFailedCRC );
00865 
00866   Returns:
00867     True if read was successful.  You need to check the value
00868     of bFailedCRC to see if the information that was read is valid.
00869   */
00870   bool ReadCompressedBuffer(
00871           size_t sizeof__outbuffer,
00872           void* outbuffer,
00873           int* bFailedCRC
00874           );
00875 
00876   /*
00877   Description:
00878     Compress buffer and write the compressed information to the archive.
00879   Parameters:
00880     sizeof__inbuffer - [in] size of the uncompressed buffer in bytes
00881     inbuffer - [in] uncompressed buffer
00882   Returns:
00883     True if write was successful.
00884   */
00885   bool WriteCompressedBuffer(
00886     size_t sizeof__inbuffer,
00887     const void* inbuffer
00888     );
00889 
00890   bool ReadBool( bool* );
00891 
00892         bool ReadChar(    // Read an array of 8 bit chars
00893                         size_t,       // number of chars to read
00894                         char*    
00895                         );  
00896         bool ReadChar(    // Read an array of 8 bit unsigned chars
00897                         size_t,       // number of unsigned chars to read
00898                         unsigned char*    
00899                         );  
00900         bool ReadChar(    // Read a single 8 bit char
00901                         char*    
00902                         );  
00903         bool ReadChar(    // Read a single 8 bit unsigned char
00904                         unsigned char*    
00905                         );  
00906 
00907         bool ReadShort(   // Read an array of 16 bit shorts
00908                         size_t,       // number of shorts to read
00909                         short*    
00910                         );  
00911         bool ReadShort(   // Read an array of 16 bit unsigned shorts
00912                         size_t,       // number of shorts to read
00913                         unsigned short*    
00914                         );  
00915         bool ReadShort(   // Read a single 16 bit short
00916                         short*    
00917                         );  
00918         bool ReadShort(   // Read a single 16 bit unsigned short
00919                         unsigned short*    
00920                         );  
00921 
00922         bool ReadInt( // Read an array of 32 bit integers
00923                         size_t,       // number of ints to read
00924                         int*      
00925                         ); 
00926         bool ReadInt( // Read an array of 32 bit integers
00927                         size_t,       // number of ints to read
00928                         unsigned int*      
00929                         ); 
00930         bool ReadInt( // Read a single 32 bit integer
00931                         int*      
00932                         ); 
00933         bool ReadInt( // Read a single 32 bit unsigned integer
00934                         unsigned int*      
00935                         ); 
00936 
00937         bool ReadBigInt( // Read an array of 64 bit integers
00938                         size_t,       // number of ints to read
00939                         ON__INT64*      
00940                         ); 
00941         bool ReadBigInt( // Read an array of 64 bit integers
00942                         size_t,       // number of ints to read
00943                         ON__UINT64*      
00944                         ); 
00945         bool ReadBigInt( // Read a single 64 bit integer
00946                         ON__INT64*      
00947                         ); 
00948         bool ReadBigInt( // Read a single 64 bit unsigned integer
00949                         ON__UINT64*      
00950                         ); 
00951 
00952         bool ReadLong( // Read an array of 32 bit integers
00953                         size_t,       // number of ints to read
00954                         long*      
00955                         ); 
00956         bool ReadLong( // Read an array of 32 bit integers
00957                         size_t,       // number of ints to read
00958                         unsigned long*      
00959                         ); 
00960         bool ReadLong( // Read a single 32 bit integer
00961                         long*      
00962                         ); 
00963         bool ReadLong( // Read a single 32 bit unsigned integer
00964                         unsigned long*      
00965                         ); 
00966         bool ReadSize( // Read a single size_t
00967                         size_t*
00968                         ); 
00969 
00970   bool ReadBigSize( size_t* ); // 64 bits
00971   
00972   bool ReadBigTime( time_t* ); // UCT seconds since 1 January 1970 (64 bits)
00973 
00974 
00975         bool ReadFloat(   // Read an array of floats
00976                         size_t,       // number of floats
00977                         float*
00978                         );
00979         bool ReadFloat(   // Read a single float
00980                         float*
00981                         );
00982         bool ReadDouble(  // Read an array of IEEE doubles
00983                         size_t,       // number of doubles
00984                         double*
00985                         );
00986         bool ReadDouble(  // Read a single double
00987                         double*
00988                         );
00989 
00990   bool ReadColor(
00991     ON_Color&
00992     );
00993 
00994   bool ReadPoint (
00995     ON_2dPoint&
00996     );
00997   bool ReadPoint (
00998     ON_3dPoint&
00999     );
01000   bool ReadPoint (
01001     ON_4dPoint&
01002     );
01003   bool ReadVector (
01004     ON_2dVector&
01005     );
01006   bool ReadVector (
01007     ON_3dVector&
01008     );
01009 
01010   bool ReadBoundingBox(ON_BoundingBox&);
01011 
01012   bool ReadXform(ON_Xform&);
01013 
01014   bool ReadPlaneEquation(ON_PlaneEquation&);
01015 
01016   bool ReadPlane(ON_Plane&);
01017 
01018   bool ReadLine(ON_Line&);
01019 
01020   bool ReadArc(ON_Arc&);
01021 
01022   bool ReadCircle(ON_Circle&);
01023 
01024   bool ReadInterval( ON_Interval& );
01025 
01026   bool ReadUuid( ON_UUID& );
01027 
01028   bool ReadDisplayMaterialRef( ON_DisplayMaterialRef& );
01029 
01030   bool ReadLinetypeSegment( ON_LinetypeSegment& );
01031 
01032   // All times are stored in coordinated universal time
01033   // ( a.k.a GMT, UTC ).  Use ANSI C time() and gmtime() calls.
01034   bool ReadTime( struct tm& );
01035 
01036   /*
01037   Parameters:
01038     str_array_count - [out]
01039       Number of elements in the string array. All ON_BinaryArchive string
01040       WriteString() functions write a null terminator to the file and
01041       the null terminator is included in the count. This means that
01042       if a string has a non-zero element, then str_array_count >= 2.
01043   Remarks:
01044     Modify your code to use ReadStringUTF8ElementCount() when reading
01045     UTF-8 encoded strings and ReadStringUTF16ElementCount()
01046     when reading UTF-16 encoded strings.
01047   */
01048   ON_DEPRECATED bool ReadStringSize(
01049       size_t* str_array_count
01050       );
01051 
01052   /*
01053   Parameters:
01054     string_utf8_element_count - [out]
01055       Number of bytes in the string array. All ON_BinaryArchive string
01056       WriteString() functions write a null terminator to the file and
01057       the null terminator is included in string_element_count. This means
01058       that if opennurbs wrote the string, either string_element_count = 0
01059       or string_element_count >= 2.
01060   */
01061   bool ReadStringUTF8ElementCount(
01062     size_t* string_utf8_element_count
01063     );
01064 
01065   /*
01066   Parameters:
01067     string_utf16_element_count - [out]
01068       Number of elements in the string array. All ON_BinaryArchive string
01069       WriteString() functions write a null terminator to the file and
01070       the null terminator is included in string_element_count. This means
01071       that if opennurbs wrote the string, either string_element_count = 0
01072       or string_element_count >= 2.
01073   */
01074   bool ReadStringUTF16ElementCount(
01075     size_t* string_utf16_element_count
01076     );
01077 
01078 
01079   /*
01080   Parameters:
01081     str_array_count - [in]
01082       Number of char elements in str_array[], including the null
01083       terminator.  The value of str_array_count is returned by
01084       ReadCharStringElementCount().
01085     str_array - [in/out]
01086       Pass in an array with at least str_array_count elements.
01087       If true is returned and str_array_count > 0,
01088       then str_array[str_array_count-1] = 0. All strings with
01089       char elements written by Rhino are UTF-8 encoded
01090       unicode strings.
01091   */
01092   bool ReadString(
01093       size_t str_array_count,
01094       char* str_array
01095       );
01096 
01097   /*
01098   Parameters:
01099     str_array_count - [in]
01100       Number of unsignd char elements in str_array[], including
01101       the null terminator. The value of str_array_count is returned
01102       by ReadCharStringElementCount().
01103     str_array - [in/out]
01104       Pass in an array with at least str_array_count elements.
01105       If true is returned and str_array_count > 0,
01106       then str_array[str_array_count-1] = 0. All strings with
01107       unsigned char elements written by Rhino are UTF-8 encoded 
01108       unicode strings.
01109   */
01110   bool ReadString(
01111       size_t str_array_count,
01112       unsigned char* str_array
01113       );
01114 
01115   /*
01116   Parameters:
01117     str_array_count - [in]
01118       Number of unsigned short elements in str_array[],
01119       including the null terminator. The value of 
01120       str_array_count is returned by ReadWideCharStringElementCount().
01121     str_array - [in/out]
01122       Pass in an array with at least str_array_count elements.
01123       If true is returned and str_array_count > 0,
01124       then str_array[str_array_count-1] = 0. All strings with
01125       unsigned short elements written by Rhino are UTF-16 encoded
01126       unicode strings.
01127   */
01128   bool ReadString(
01129       size_t str_array_count,
01130       unsigned short*  str_array
01131       );
01132 
01133   bool ReadString( ON_String& sUTF8 );
01134 
01135   bool ReadString( ON_wString& s );
01136 
01137   bool ReadComponentIndex( ON_COMPONENT_INDEX& );
01138 
01139   bool ReadArray( ON_SimpleArray<bool>& );
01140   bool ReadArray( ON_SimpleArray<char>& );
01141   bool ReadArray( ON_SimpleArray<short>& );
01142   bool ReadArray( ON_SimpleArray<int>& );
01143   bool ReadArray( ON_SimpleArray<float>& );
01144   bool ReadArray( ON_SimpleArray<double>& );
01145   bool ReadArray( ON_SimpleArray<ON_Color>& );
01146   bool ReadArray( ON_SimpleArray<ON_2dPoint>& );
01147   bool ReadArray( ON_SimpleArray<ON_3dPoint>& );
01148   bool ReadArray( ON_SimpleArray<ON_4dPoint>& );
01149   bool ReadArray( ON_SimpleArray<ON_2dVector>& );
01150   bool ReadArray( ON_SimpleArray<ON_3dVector>& );
01151   bool ReadArray( ON_SimpleArray<ON_Xform>& );
01152   bool ReadArray( ON_SimpleArray<ON_2fPoint>& );
01153   bool ReadArray( ON_SimpleArray<ON_3fPoint>& );
01154   bool ReadArray( ON_SimpleArray<ON_4fPoint>& );
01155   bool ReadArray( ON_SimpleArray<ON_2fVector>& );
01156   bool ReadArray( ON_SimpleArray<ON_3fVector>& );
01157   bool ReadArray( ON_SimpleArray<ON_UUID>& );
01158   bool ReadArray( ON_SimpleArray<ON_UuidIndex>& );
01159   bool ReadArray( ON_SimpleArray<ON_SurfaceCurvature>& );
01160   bool ReadArray( ON_ClassArray<ON_String>& );
01161   bool ReadArray( ON_ClassArray<ON_wString>& );
01162   bool ReadArray( ON_SimpleArray<ON_DisplayMaterialRef>& );
01163   bool ReadArray( ON_SimpleArray<ON_LinetypeSegment>& );  
01164   bool ReadArray( ON_SimpleArray<ON_MappingChannel>& );
01165   bool ReadArray( ON_ClassArray<ON_MaterialRef>& );
01166   bool ReadArray( ON_ClassArray<ON_MappingRef>& );
01167   bool ReadArray( ON_ClassArray<class ON_ObjRef>& );
01168   bool ReadArray( ON_SimpleArray<class ON_ObjRef_IRefID>& );
01169   bool ReadArray( ON_SimpleArray<class ON_ClippingPlaneInfo>& );
01170   bool ReadArray( ON_ObjectArray<class ON_Layer>& );
01171   bool ReadArray( ON_SimpleArray<class ON_Layer*>& );
01172 
01173   bool WriteBool( bool );
01174 
01175   bool WriteChar(    // Write an array of 8 bit chars
01176                         size_t,       // number of chars to write
01177                         const char*    
01178                         );  
01179         bool WriteChar(    // Write an array of 8 bit unsigned chars
01180                         size_t,       // number of unsigned chars to write
01181                         const unsigned char*    
01182                         );  
01183         bool WriteChar(    // Write a single 8 bit char
01184                         char
01185                         );  
01186         bool WriteChar(    // Write a single 8 bit unsigned char
01187                         unsigned char
01188                         );  
01189 
01190         bool WriteShort(   // Write an array of 16 bit shorts
01191                         size_t,       // number of shorts to write
01192                         const short*    
01193                         );  
01194         bool WriteShort(   // Write an array of 16 bit unsigned shorts
01195                         size_t,       // number of shorts to write
01196                         const unsigned short*    
01197                         );  
01198         bool WriteShort(   // Write a single 16 bit short
01199                         short
01200                         );  
01201         bool WriteShort(   // Write a single 16 bit unsigned short
01202                         unsigned short
01203                         );  
01204 
01205         bool WriteInt( // Write an array of 32 bit integers
01206                         size_t,       // number of ints to write
01207                         const int*      
01208                         ); 
01209         bool WriteInt( // Write an array of 32 bit integers
01210                         size_t,       // number of ints to write
01211                         const unsigned int*      
01212                         ); 
01213         bool WriteInt( // Write a single 32 bit integer
01214                         int    
01215                         ); 
01216         bool WriteInt( // Write a single 32 bit unsigned integer
01217                         unsigned int
01218                         ); 
01219 
01220         bool WriteBigInt( // Write an array of 64 bit integers
01221                         size_t,       // number of ints to write
01222                         const ON__INT64*      
01223                         ); 
01224         bool WriteBigInt( // Write an array of 64 bit integers
01225                         size_t,       // number of ints to write
01226                         const ON__UINT64*      
01227                         ); 
01228         bool WriteBigInt( // Write a single 64 bit integer
01229                         ON__INT64    
01230                         ); 
01231         bool WriteBigInt( // Write a single 64 bit unsigned integer
01232                         ON__UINT64
01233                         ); 
01234 
01235         bool WriteLong( // Write an array of 32 bit integers
01236                         size_t,       // number of ints to write
01237                         const long*      
01238                         ); 
01239         bool WriteLong( // Write an array of 32 bit integers
01240                         size_t,       // number of ints to write
01241                         const unsigned long*      
01242                         ); 
01243         bool WriteLong( // Write a single 32 bit integer
01244                         long    
01245                         ); 
01246         bool WriteLong( // Write a single 32 bit unsigned integer
01247                         unsigned long
01248                         ); 
01249         bool WriteSize( // Write a single size_t
01250                         size_t
01251                         ); 
01252 
01253   bool WriteBigSize( size_t ); // 64 bits 
01254   
01255   bool WriteBigTime( time_t ); // UCT seconds since 1 January 1970 (64 bits)
01256 
01257         bool WriteFloat(   // Write a number of IEEE floats
01258                         size_t,       // number of doubles
01259                         const float*
01260                         );
01261         bool WriteFloat(   // Write a single float
01262                         float
01263                         );
01264         bool WriteDouble(  // Write a single double
01265       size_t,
01266                         const double*
01267                         );
01268         bool WriteDouble(  // Write a single double
01269                         double
01270                         );
01271 
01272   bool WriteColor (
01273     const ON_Color&
01274     );
01275 
01276   bool WritePoint (
01277     const ON_2dPoint&
01278     );
01279   bool WritePoint (
01280     const ON_3dPoint&
01281     );
01282   bool WritePoint (
01283     const ON_4dPoint&
01284     );
01285   bool WriteVector (
01286     const ON_2dVector&
01287     );
01288   bool WriteVector (
01289     const ON_3dVector&
01290     );
01291 
01292   bool WriteBoundingBox(const ON_BoundingBox&);
01293 
01294   bool WriteXform(const ON_Xform&);
01295 
01296   bool WritePlaneEquation(const ON_PlaneEquation&);
01297 
01298   bool WritePlane(const ON_Plane&);
01299 
01300   bool WriteLine(const ON_Line&);
01301 
01302   bool WriteArc(const ON_Arc&);
01303 
01304   bool WriteCircle(const ON_Circle&);
01305 
01306   bool WriteInterval( const ON_Interval& );
01307 
01308   bool WriteUuid( const ON_UUID& );
01309 
01310   bool WriteDisplayMaterialRef( const ON_DisplayMaterialRef& );
01311 
01312   bool WriteLinetypeSegment( const ON_LinetypeSegment& );
01313 
01314   // All times are stored in universal coordinated time
01315   // ( a.k.a GMT, UCT ).  Use ANSI C time() and gmtime() calls.
01316   bool WriteTime( const struct tm& );
01317 
01318   /*
01319   Parameters:
01320     sUTF8 - [in]
01321       A null terminated UTF-8 encoded unicode string.
01322   Remarks:
01323     To read a string written with WriteString(const char*),
01324     call ReadStringUTF8ElementCount(&string_utf8_element_count)
01325     to get the number of char elements written in the file,
01326     obtain a buffer with at least string_utf8_element_count
01327     char elements and then call 
01328     ReadString(string_utf8_element_count,buffer) to read the
01329     char elements.
01330 
01331     If 0 == sUTF8 or 0 == SUTF8[0], a 4 byte int with
01332     value = 0 is written, otherwise a 4 byte int with
01333     value = strlen + 1 is written, followed by the string,
01334     followed by the null terminator.
01335   */
01336   bool WriteString(
01337       const char* sUTF8         
01338       );
01339 
01340   /*
01341   Parameters:
01342     sUTF8 - [in]
01343       A null terminated UTF-8 encoded unicode string.
01344   Remarks:
01345     To read a string written with WriteString(const unsigned char*),
01346     call ReadStringUTF8ElementCount(&string_utf8_element_count) to
01347     get the number of unsigned char elements written in the file,
01348     obtain a buffer with at least string_utf8_element_count
01349     unsigned char elements and then call 
01350     ReadString(string_utf8_element_count,buffer) to read the 
01351     unsigned charelements.
01352 
01353     If 0 == sUTF8 or 0 == SUTF8[0], a 4 byte int with
01354     value = 0 is written, otherwise a 4 byte int with
01355     value = strlen + 1 is written, followed by the string,
01356     followed by the null terminator.
01357   */
01358   bool WriteString(
01359       const unsigned char* sUTF8
01360       );
01361 
01362   /*
01363   Parameters:
01364     sUTF16 - [in]
01365       A null terminated UTF-16 encoded unicode string.
01366   Remarks:
01367     To read a string written with WriteString(const unsigned short*),
01368     call ReadStringUTF16ElementCount(&string_utf16_element_count) to
01369     get the number of unsigned short elements written in the file,
01370     obtain a buffer with at least string_utf16_element_count
01371     unsigned short elements and then call 
01372     ReadString(string_utf16_element_count,buffer) to read the
01373     unsigned short elements.
01374 
01375     If 0 == sUTF8 or 0 == SUTF8[0], a 4 byte int with
01376     value = 0 is written, otherwise a 4 byte int with
01377     value = strlen + 1 is written, followed by the string,
01378     followed by the null terminator.
01379   */
01380   bool WriteString(
01381       const unsigned short* sUTF16
01382       );
01383   
01384   bool WriteString( const ON_String& sUTF8 );
01385 
01386   bool WriteString( const ON_wString& s);
01387 
01388   bool WriteComponentIndex( const ON_COMPONENT_INDEX& );
01389 
01390   bool WriteArray( const ON_SimpleArray<bool>& );
01391   bool WriteArray( const ON_SimpleArray<char>& );
01392   bool WriteArray( const ON_SimpleArray<short>& );
01393   bool WriteArray( const ON_SimpleArray<int>& );
01394   bool WriteArray( const ON_SimpleArray<float>& );
01395   bool WriteArray( const ON_SimpleArray<double>& );
01396 
01397   bool WriteArray( const ON_SimpleArray<ON_Color>& );
01398 
01399   bool WriteArray( const ON_SimpleArray<ON_2dPoint>& );
01400   bool WriteArray( const ON_SimpleArray<ON_3dPoint>& );
01401   bool WriteArray( const ON_SimpleArray<ON_4dPoint>& );
01402   bool WriteArray( const ON_SimpleArray<ON_2dVector>& );
01403   bool WriteArray( const ON_SimpleArray<ON_3dVector>& );
01404 
01405   bool WriteArray( const ON_SimpleArray<ON_2fPoint>& );
01406   bool WriteArray( const ON_SimpleArray<ON_3fPoint>& );
01407   bool WriteArray( const ON_SimpleArray<ON_4fPoint>& );
01408   bool WriteArray( const ON_SimpleArray<ON_2fVector>& );
01409   bool WriteArray( const ON_SimpleArray<ON_3fVector>& );
01410   bool WriteArray( const ON_SimpleArray<ON_Xform>& );
01411   bool WriteArray( const ON_SimpleArray<ON_UUID>& );
01412   bool WriteArray( const ON_SimpleArray<ON_UuidIndex>& );
01413   bool WriteArray( const ON_SimpleArray<ON_SurfaceCurvature>& );
01414   bool WriteArray( const ON_ClassArray<ON_String>& );
01415   bool WriteArray( const ON_ClassArray<ON_wString>& );
01416   bool WriteArray( const ON_SimpleArray<ON_DisplayMaterialRef>& );
01417   bool WriteArray( const ON_SimpleArray<ON_LinetypeSegment>& );  
01418   bool WriteArray( const ON_SimpleArray<ON_MappingChannel>& );
01419   bool WriteArray( const ON_ClassArray<ON_MaterialRef>& );
01420   bool WriteArray( const ON_ClassArray<ON_MappingRef>& );
01421   bool WriteArray( const ON_ClassArray<class ON_ObjRef>& );
01422   bool WriteArray( const ON_SimpleArray<class ON_ObjRef_IRefID>& );
01423   bool WriteArray( const ON_SimpleArray<class ON_ClippingPlaneInfo>& );
01424   bool WriteArray( int count, const class ON_Layer* );
01425   bool WriteArray( int count, const class ON_Layer*const* );
01426 
01428   //
01429   // Read/Write classes derived from ON_Object
01430   //
01431 
01432   /*
01433   Description:
01434     Reads and object from a 3dm archive;
01435   Parameters:
01436     ppObject - [out]  object is allocated and a pointer to the
01437                       allocated object is returned as *ppObject;
01438   Returns:
01439     0: failure - unable to read object because of file IO problems
01440     1: success
01441     3: unable to read object because it's UUID is not registered
01442        this could happen in cases where old code is attempting to read
01443        new objects.
01444   */
01445   int ReadObject( 
01446          ON_Object** ppObject
01447          );
01448 
01449 
01450   /*
01451   Description:
01452     Reads and object from a 3dm archive.
01453   Parameters:
01454     object - [in] The value of object.ON_ClassId()->Uuid() must
01455                   exactly match the class uuid in of the next
01456                   object in the archive.
01457   Returns:
01458     0: failure - unable to read object because of file IO problems.
01459     1: success
01460     2: unable to read object because the class id in the archive
01461        did not match pObject->ClassId.
01462   */
01463   int ReadObject( 
01464          ON_Object& object
01465          );
01466 
01467   bool WriteObject( const ON_Object* ); // writes object definition
01468   bool WriteObject( const ON_Object& ); // writes object definition
01469 
01470 
01473   //
01474   // 3DM Interface - ignore if not reading/writing a 3DM file
01475   //                 this is here so that the infrastructure
01476   //                 for writing 3dm archives is available for
01477   //                 any type of serialization device.
01478   //
01479   bool EnableSave3dmRenderMeshes( ON_BOOL32 = true ); // returns previous state
01480   bool Save3dmRenderMeshes() const;
01481 
01482   bool EnableSave3dmAnalysisMeshes( ON_BOOL32 = true ); // returns previous state
01483   bool Save3dmAnalysisMeshes() const;
01484   
01485   bool EnableSaveUserData( ON_BOOL32 = true ); // returns previous state
01486   bool SaveUserData() const;
01487   
01488   /*
01489   Returns:
01490     50 (The Rhino 5.0 opennurbs file version.)
01491     This is the value of version to pass to ON_BinaryArchive
01492     functions like Write3dmStartSection() when you want to use the 
01493     the current opennurbs version number and you do not want to have
01494     to update your code when this version number changes.    
01495   */
01496   static int CurrentArchiveVersion();
01497 
01499   // Step 1: REQUIRED - Write/Read Start Section
01500   //
01501 
01502   /*
01503   Parameters:
01504     version - [in]
01505        0, 2, 3, 4, 5 or 50 (5 is treated as 50)
01506        
01507        If version is 0, then the value of ON_BinaryArchive::CurrentArchiveVersion()
01508        is used.
01509 
01510        Use either 0 or the value of ON_BinaryArchive::CurrentArchiveVersion()
01511        for the version parameter when you want your code to write the most 
01512        up to date file version. 
01513 
01514     sStartSectionComment - [in]
01515       NULL or ASCII string with application name, et cetera.
01516       This information is primarily used when debugging files
01517       that contain problems.  McNeel and Associates stores
01518       application name, application version, compile date, 
01519       and the OS in use when file was written.
01520   */
01521   bool Write3dmStartSection( 
01522         int version,
01523         const char* sStartSectionComment
01524         );
01525 
01526   /*
01527   Parameters:
01528     version - [out]
01529        .3dm file version (2, 3, 4, 5 or 50)
01530     sStartSectionComment - [out]
01531       string passed to Write3dmStartSection()
01532   */
01533   bool Read3dmStartSection( 
01534         int* version,
01535         ON_String& sStartSectionComment
01536         );
01537 
01539   // Step 2: REQUIRED - Write/Read properties table
01540   //
01541   bool Write3dmProperties(
01542         const ON_3dmProperties&
01543         );
01544   bool Read3dmProperties(
01545         ON_3dmProperties&
01546         );
01547 
01549   // Step 3: REQUIRED - Write/Read settings table
01550   //
01551   bool Write3dmSettings(
01552         const ON_3dmSettings&
01553         );
01554   bool Read3dmSettings(
01555         ON_3dmSettings&
01556         );
01557 
01559   // Step 4: REQUIRED - Write/Read bitmap table (it can be empty)
01560   //
01561   bool BeginWrite3dmBitmapTable();
01562   bool Write3dmBitmap( const ON_Bitmap& );
01563   bool EndWrite3dmBitmapTable();
01564 
01565   bool BeginRead3dmBitmapTable();
01566   int  Read3dmBitmap(   // returns 0 at end of light table
01567                         //         1 bitmap successfully read
01568             ON_Bitmap** // bitmap returned here
01569             );
01570   bool EndRead3dmBitmapTable();
01571 
01573   // Step 5: REQUIRED - Write/Read render material table (it can be empty)
01574   //
01575   bool BeginWrite3dmTextureMappingTable();
01576   bool Write3dmTextureMapping( const ON_TextureMapping& );
01577   bool EndWrite3dmTextureMappingTable();
01578 
01579   bool BeginRead3dmTextureMappingTable();
01580   int  Read3dmTextureMapping( // returns 0 at end of table
01581             ON_TextureMapping** // layer returned here
01582             );
01583   bool EndRead3dmTextureMappingTable();
01584 
01586   // Step 6: REQUIRED - Write/Read render material table (it can be empty)
01587   //
01588   bool BeginWrite3dmMaterialTable();
01589   bool Write3dmMaterial( const ON_Material& );
01590   bool EndWrite3dmMaterialTable();
01591 
01592   bool BeginRead3dmMaterialTable();
01593   int  Read3dmMaterial( // returns 0 at end of table
01594             ON_Material** // layer returned here
01595             );
01596   bool EndRead3dmMaterialTable();
01597 
01599   // Step 7: REQUIRED - Write/Read linetype table (it can be empty)
01600   //
01601   bool BeginWrite3dmLinetypeTable();
01602   bool Write3dmLinetype( const ON_Linetype&);
01603   bool EndWrite3dmLinetypeTable();
01604 
01605   bool BeginRead3dmLinetypeTable();
01606   int  Read3dmLinetype(ON_Linetype**);
01607   bool EndRead3dmLinetypeTable();
01608 
01610   // Step 8: REQUIRED - Write/Read layer table (it can be empty)
01611   //
01612   bool BeginWrite3dmLayerTable();
01613   bool Write3dmLayer( const ON_Layer& );
01614   bool EndWrite3dmLayerTable();
01615 
01616   bool BeginRead3dmLayerTable();
01617   int  Read3dmLayer( // returns 0 at end of table
01618             ON_Layer** // layer returned here
01619             );
01620   bool EndRead3dmLayerTable();
01621 
01623   // Step 9: REQUIRED - Write/Read group table (it can be empty)
01624   //
01625   bool BeginWrite3dmGroupTable();
01626   bool Write3dmGroup( const ON_Group& );
01627   bool EndWrite3dmGroupTable();
01628 
01629   bool BeginRead3dmGroupTable();
01630 
01631   // Description:
01632   //   Reads groups from group table.  If the group definition is
01633   //   read, a group is created by calling new ON_Group(),
01634   //   initialized with values stored in the archive, and 
01635   //   returned.
01636   //
01637   // Parameters:
01638   //   ppGroup - If the group definition is
01639   //   read, a group is created by calling new ON_Group(),
01640   //   initialized with values stored in the archive, and 
01641   //   a pointer to the new group is returned in *ppGroup.
01642   //
01643   // Returns:
01644   //
01645   //   @untitled table
01646   //   0     at the end of the group table
01647   //   1     group definition was successfully read
01648   //   -1    archive is corrupt at this point
01649   //
01650   // Example:
01651   //   Calls to Read3dmGroup need to be bracketed by calls
01652   //   to BeginRead3dmGroupTable() / EndRead3dmGroupTable().
01653   //
01654   //           archive.BeginRead3dmGroupTable();
01655   //           ON_Group* pGroup;
01656   //           int rc = 1;
01657   //           while(rc==1)
01658   //           { //
01659   //             pGroup = 0;
01660   //             archive.Read3dmGroup(&pGroup);
01661   //             if ( pGroup )
01662   //               do something with pGroup
01663   //           } //
01664   //           archive.EndRead3dmGroupTable();
01665   //      
01666   int  Read3dmGroup(
01667             ON_Group** // ppGroup
01668             );
01669 
01670   bool EndRead3dmGroupTable();
01671 
01672 
01674   // Step 10: REQUIRED - Write/Read font table (it can be empty)
01675   //
01676   bool BeginWrite3dmFontTable();
01677   bool Write3dmFont( const ON_Font& );
01678   bool EndWrite3dmFontTable();
01679 
01680   bool BeginRead3dmFontTable();
01681 
01682   // Description:
01683   //   Reads fonts from font table.  If the font definition is
01684   //   read, a font is created by calling new ON_Font(),
01685   //   initialized with values stored in the archive, and 
01686   //   returned.
01687   //
01688   // Parameters:
01689   //   ppFont - If the font definition is
01690   //   read, a font is created by calling new ON_Font(),
01691   //   initialized with values stored in the archive, and 
01692   //   a pointer to the new font is returned in *ppFont.
01693   //
01694   // Returns:
01695   //
01696   //   @untitled table
01697   //   0     at the end of the font table
01698   //   1     font definition was successfully read
01699   //   -1    archive is corrupt at this point
01700   //
01701   // Example:
01702   //   Calls to Read3dmFont need to be bracketed by calls
01703   //   to BeginRead3dmFontTable() / EndRead3dmFontTable().
01704   //
01705   //           archive.BeginRead3dmFontTable();
01706   //           int rc = 1;
01707   //           ON_Font* pFont;
01708   //           while(rc==1)
01709   //           { //
01710   //             pFont = 0;
01711   //             archive.Read3dmFont(&pFont);
01712   //             if ( pFont )
01713   //               do something with pFont
01714   //           } //
01715   //           archive.EndRead3dmFontTable();
01716   //      
01717   int Read3dmFont(
01718             ON_Font** // ppFont
01719             );
01720 
01721   bool EndRead3dmFontTable();
01722 
01723 
01725   // Step 11: REQUIRED - Write/Read dimstyle table (it can be empty)
01726   //
01727   bool BeginWrite3dmDimStyleTable();
01728   bool Write3dmDimStyle( const ON_DimStyle& );
01729   bool EndWrite3dmDimStyleTable();
01730 
01731   bool BeginRead3dmDimStyleTable();
01732 
01733   // Description:
01734   //   Reads annotation dimension styles from dimension style table.
01735   //   If the dimension style definition is read, 
01736   //   a dimension style is created by calling new ON_DimStyle(),
01737   //   initialized with values stored in the archive, and 
01738   //   returned.
01739   //
01740   // Parameters:
01741   //   ppDimStyle - If the dimstyle definition is
01742   //   read, a dimstyle is created by calling new ON_DimStyle(),
01743   //   initialized with values stored in the archive, and 
01744   //   a pointer to the new dimstyle is returned in *ppDimStyle.
01745   //
01746   // Returns:
01747   //
01748   //   @untitled table
01749   //   0     at the end of the dimension style table
01750   //   1     dimension style definition was successfully read
01751   //   -1    archive is corrupt at this point
01752   //
01753   // Example:
01754   //   Calls to Read3dmDimStyle need to be bracketed by calls
01755   //   to BeginRead3dmDimStyleTable() / EndRead3dmDimStyleTable().
01756   //
01757   //           archive.BeginRead3dmDimStyleTable();
01758   //           int rc = 1;
01759   //           ON_DimStyle* pDimStyle;
01760   //           while(rc==1)
01761   //           { //
01762   //             pDimStyle = 0;
01763   //             archive.Read3dmDimStyle(&pDimStyle);
01764   //             if ( pDimStyle )
01765   //               do something with pDimStyle
01766   //           } //
01767   //           archive.EndRead3dmDimStyleTable();
01768   //      
01769   int Read3dmDimStyle(
01770             ON_DimStyle** // ppDimStyle
01771             );
01772 
01773   bool EndRead3dmDimStyleTable();
01774 
01775 
01777   // Step 12: REQUIRED - Write/Read render light table (it can be empty)
01778   //
01779   bool BeginWrite3dmLightTable();
01780   bool Write3dmLight( const ON_Light&,
01781          const ON_3dmObjectAttributes* // optional
01782          );
01783   bool EndWrite3dmLightTable();
01784 
01785   bool BeginRead3dmLightTable();
01786   int  Read3dmLight(  // returns 0 at end of light table
01787                       //         1 light successfully read
01788                       //        -1 if file is corrupt
01789             ON_Light**, // light returned here
01790             ON_3dmObjectAttributes* // optional - if NOT NULL, object attributes are
01791                                     //            returned here
01792             );
01793   bool EndRead3dmLightTable();
01794 
01795 
01797   // Step 13: REQUIRED - Write/Read hatch pattern table (it can be empty)
01798   //
01799   bool BeginWrite3dmHatchPatternTable();
01800   bool Write3dmHatchPattern( const ON_HatchPattern&);
01801   bool EndWrite3dmHatchPatternTable();
01802 
01803   bool BeginRead3dmHatchPatternTable();
01804   int  Read3dmHatchPattern(ON_HatchPattern**);
01805   bool EndRead3dmHatchPatternTable();
01806 
01808   // Step 14: REQUIRED - Write/Read instance definition table (it can be empty)
01809   //
01810   bool BeginWrite3dmInstanceDefinitionTable();
01811   bool Write3dmInstanceDefinition( const ON_InstanceDefinition& );
01812   bool EndWrite3dmInstanceDefinitionTable();
01813 
01814   bool BeginRead3dmInstanceDefinitionTable();
01815 
01816   /*
01817    Description:
01818      Reads instance definitions from instance defintion table.
01819   
01820    Parameters:
01821      ppInstanceDefinition - If an instance defintion is
01822      read, an instance defintion is created by calling new 
01823      ON_InstanceDefinition(), initialized with values stored
01824      in the archive, and a pointer to the new instance defintion
01825      is returned in *ppInstanceDefinition.
01826   
01827    Returns:
01828   
01829      @untitled table
01830      0     at the end of the instance defintion table
01831      1     instance defintion was successfully read
01832      -1    archive is corrupt at this point
01833   
01834    Example:
01835      Calls to Read3dmInstanceDefinition need to be bracketed by calls
01836      to BeginRead3dmInstanceDefinitionTable() / EndRead3dmInstanceDefinitionTable().
01837   
01838              archive.BeginRead3dmInstanceDefinitionTable();
01839              int rc = 1;
01840              ON_InstanceDefinition* pInstanceDefinition;
01841              while(rc==1)
01842              { 
01843                pInstanceDefinition = 0;
01844                archive.Read3dmInstanceDefinition(&pInstanceDefinition);
01845                if ( pInstanceDefinition )
01846                  do something with pInstanceDefinition
01847              } 
01848              archive.EndRead3dmInstanceDefinitionTable();
01849   */      
01850   int Read3dmInstanceDefinition(
01851             ON_InstanceDefinition** // ppInstanceDefinition
01852             );
01853 
01854   bool EndRead3dmInstanceDefinitionTable();
01855 
01857   // Step 15: REQUIRED - Write/Read geometry and annotation table (it can be empty)
01858   //
01859   bool BeginWrite3dmObjectTable();
01860   bool Write3dmObject( 
01861          const ON_Object&,
01862          const ON_3dmObjectAttributes* // optional
01863          );
01864   bool EndWrite3dmObjectTable();
01865 
01866   bool BeginRead3dmObjectTable();
01867   int  Read3dmObject( // returns 0 at end of object table
01868                       //         1 if object is read
01869                       //         2 if object is skipped because it does not match filter
01870                       //        -1 if file is corrupt
01871           ON_Object**, // object returned here (NULL if skipped)
01872           ON_3dmObjectAttributes*, // optional - if NOT NULL, object attributes are
01873                                    //            returned here
01874           unsigned int = 0 // optional filter made by setting ON::object_type bits
01875           );  // returns NULL at end of object table
01876   bool EndRead3dmObjectTable();
01877 
01879   // Step 16: REQUIRED - Write/Read history record table (it can be empty)
01880   //
01881   bool BeginWrite3dmHistoryRecordTable();
01882   bool Write3dmHistoryRecord( 
01883          const class ON_HistoryRecord&
01884          );
01885   bool EndWrite3dmHistoryRecordTable();
01886 
01887   bool BeginRead3dmHistoryRecordTable();
01888 
01889   /*
01890   Returns:
01891            0 at end of object table
01892            1 if object is read
01893           -1 if file is corrupt
01894   */
01895   int  Read3dmHistoryRecord(
01896           class ON_HistoryRecord*&
01897           );
01898   bool EndRead3dmHistoryRecordTable();
01899 
01901   // Step 17: OPTIONAL - Write/Read 0 or more user tables
01902   //
01903 
01904   /*
01905   Description:
01906     Write the user table header information that must precede
01907     the user table information written by a plug-in.
01908   Parameters:
01909     plugin_id - [in]
01910     bSavingGoo - [in]
01911       Set to false if a plug-in will be used to write
01912       the user table.  Set to true if a user table written by
01913       a missing plug-in is being resaved. In this case,
01914       goo_3dm_version and goo_opennurbs_version must also be
01915       set.  In practice, you should use Write3dmAnonymousUserTableRecord()
01916       to handle writing "goo" and use this function only when
01917       the plug-in in present.
01918     goo_3dm_version - [in]
01919       If bSavingGoo is false, this parameter must be zero and
01920       ON_BinaryArchive::Archive3dmVersion() will be used.
01921       If bSavingGoo is true, this parameter must be the version of 
01922       the 3dm archive (1,2,3,4,5,50,...) the plug-in code used to 
01923       write the user table.
01924     goo_opennurbs_version - [in]
01925       If bSavingGoo is false, this parameter must be zero and
01926       ON_BinaryArchive::ArchiveOpenNURBSVersion() will be used.
01927       If bSavingGoo is true, this parameter must be the version
01928       of the opennurbs (YYYYMMDDN) the plug-in code used to 
01929       write the user table.
01930   Returns:
01931     True if the the user information can be written.
01932     False if user informtion should not be written.
01933   */
01934   bool BeginWrite3dmUserTable(
01935     const ON_UUID& plugin_id,
01936     bool bSavingGoo,
01937     int goo_3dm_version,
01938     int goo_opennurbs_version
01939     );
01940 
01941   bool EndWrite3dmUserTable();
01942 
01943   /*
01944   Description:
01945     If Read3dmAnaonymousUserTable() was used to read ON_3dmGoo because a 
01946     plug-in was not present, then use Write3dmAnonymousUserTableRecord()
01947     to put than information back into the archive.
01948     Write3dmAnonymousUserTableRecord() writes the entire record.
01949     Do NOT call BeginWrite3dmUserTable() / EndWrite3dmUserTable() when
01950     using Write3dmAnonymousUserTableRecord().
01951   Parameters:
01952     plugin_id - [in]
01953     goo_version - [in]
01954       The version of the archive (1,2,3,4,5,50,...) that was used when
01955       the plug-in wrote the user table.
01956     goo_opennurbs_version - [in]
01957       The version of opennurbs ( YYYMMDDN ) that was used when the 
01958       plug-in wrote the user table.
01959     goo - [in]
01960   Returns:
01961     True if the goo was written or skipped because it could not be robustly
01962     saved.  False if a catastrophic IO error occured.
01963   */
01964   bool Write3dmAnonymousUserTableRecord( 
01965     const ON_UUID& plugin_id,
01966     int goo_3dm_version,
01967     int goo_opennurbs_version,
01968     const ON_3dmGoo& goo
01969     );
01970 
01971   // OBSOLETE - use BeginWrite3dmUserTable(plugin_id, bSavingGoo, 3dm_version, opennurbs_version )
01972   ON_DEPRECATED bool BeginWrite3dmUserTable( const ON_UUID& );
01973 
01974   // OBSOLETE - use Write3dmAnonymousUserTableRecord(plugin_id, ..., goo)
01975   ON_DEPRECATED bool Write3dmAnonymousUserTable( const ON_3dmGoo& );
01976 
01977   /*
01978   Parameters:
01979     plugin_id - [out] 
01980       id of plug-in that wrote the user table
01981     bLastSavedAsGoo - [out] 
01982       True if this table was saved into this archive as goo because
01983       the plug-in was not present at the time of the save.
01984     archive_3dm_version - [out]
01985       Version of the archive the plug-in wrote to.  When bLastSavedAsGoo
01986       is true, this number can be different from Archive3dmVersion().
01987     archive_opennurbs_version - [out]
01988       Version of opennurbs the plug-in used to write the archive.  
01989       When bLastSavedAsGoo is true, this number can be different 
01990       from ArchiveOpenNURBSVersion().     
01991   Returns:
01992     False when there are no more user tables or an IO error occurs.
01993   */
01994   bool BeginRead3dmUserTable(
01995     ON_UUID& plugin_id,
01996     bool* bLastSavedAsGoo,
01997     int* archive_3dm_version,
01998     int* archive_opennurbs_version
01999     );
02000 
02001   /*
02002   Description:
02003     If the plug-in that wrote the user table is not present and you need
02004     to read and resave the user table, then use Read3dmAnonymousUserTable()
02005     to load the information into "goo".
02006     If you do not need to resave the information, then simply call EndRead3dmUserTable()
02007     to skip over this table.
02008   */
02009   bool Read3dmAnonymousUserTable( 
02010     int archive_3dm_version,
02011     int archive_opennurbs_version,
02012     ON_3dmGoo& goo
02013     );
02014 
02015   bool EndRead3dmUserTable();
02016 
02017   // OBSOLETE - use BeginRead3dmUserTable( plugin_id, bLastSavedAsGoo, archive_3dm_version, ... )
02018   ON_DEPRECATED bool BeginRead3dmUserTable(
02019     ON_UUID&
02020     );
02021 
02022   // OBSOLETE - use Read3dmAnonymousUserTable( archive_3dm_version, archive_opennurbs_version, goo )
02023   ON_DEPRECATED bool Read3dmAnonymousUserTable( ON_3dmGoo& );
02024 
02025 
02026 
02027 
02029   // Step 18: REQUIRED when writing / OPTIONAL when reading
02030   //         Write end of file marker.  This information is primarily
02031   //         used when debugging files to make sure the end of the file
02032   //         hasn't been cut off.
02033   //
02034 
02035   // Description:
02036   //   Writes a TCODE_ENDOFFILE chunk that contains the number
02037   //   of bytes in the archive.
02038   //
02039   // Returns:
02040   //   true if successful, false if unable to write to archive.
02041   bool Write3dmEndMark();
02042 
02043   // Description:
02044   //   Checks for a TCODE_ENDOFFILE chunk at the current position.
02045   //   If it finds one, it reads it and returns the number
02046   //   of bytes in the archive.  Comparing this number with
02047   //   the current file position can help detect files that
02048   //   have been damaged by loosing sections.
02049   //
02050   // Parameters:
02051   //   sizeof_archive - [out] number of bytes written to archive
02052   //
02053   // Returns:
02054   //   true if successful, false if unable to find or read
02055   //   a TCODE_ENDOFFILE chunk.
02056   bool Read3dmEndMark( 
02057            size_t* // sizeof_archive
02058            );
02059 
02062   // Low level tools to  Write/Read chunks. See opennurbs_3dm.h for details
02063   // about the structure of chunks.  Every chunk must begin with a
02064   // call to BeginWrite/ReadChunk().
02065   // If BeginWriteChunk()/BeginReadChunk() returns true, then
02066   // you must call EndWrite/ReadChunk() or cease using the archive.
02067 
02068   // Description:
02069   //   Writes a chunk header containing 4 byte typecode and value.
02070   //
02071   // Parameters:
02072   //   typecode - [in] a TCODE_* number from opennurbs_3dm.h
02073   //   value    - [in] if (typecode&TCODE_SHORT) is nonzero, then
02074   //              this is the value to be saved.  Othewise, pass
02075   //              a zero and the EndWrite3dmChunk() call will
02076   //              store the length of the chunk.
02077   //
02078   // Returns:
02079   //   true if write was successful.
02080   bool BeginWrite3dmChunk(
02081         unsigned int, // typecode
02082         int // value
02083         );
02084 
02085   bool BeginWrite3dmBigChunk(
02086         ON__UINT32 typecode,
02087         ON__INT64 value
02088         );
02089 
02090   /*
02091   Description:
02092     Begins writing a chunk.
02093   Parameters:
02094     tcode - [in] chunk's typecode from opennurbs_3dm.h.  This cannot be a short tcode.
02095     major_version - [in] ( >= 1)
02096     minor_version - [in] ( >= 0 )
02097   Returns:
02098     True if input was valid and chunk was started.  In this case
02099     You must call EndWrite3dmChunk(), even if something goes wrong
02100     while you attempt to write the contents of the chunk.
02101     False if input was not valid or the write failed.
02102   */
02103   bool BeginWrite3dmChunk(
02104         unsigned int tcode,
02105         int major_version,
02106         int minor_version
02107         );
02108 
02109 
02110   // updates length in chunk header
02111   bool EndWrite3dmChunk();
02112 
02113   bool Write3dmGoo( const ON_3dmGoo& ); // call to write "goo"
02114 
02115   // OBSOLETE - Use BeginRead3dmBigChunk()
02116   ON_DEPRECATED bool BeginRead3dmChunk(
02117         unsigned int*,   // typecode from opennurbs_3dm.h
02118         int*             // value
02119         );
02120 
02121   // When the end of the 3dm file is reached, BeginReadChunk() will
02122   // return true with a typecode of TCODE_ENDOFFILE.
02123   bool BeginRead3dmBigChunk(
02124         unsigned int*,   // typecode from opennurbs_3dm.h
02125         ON__INT64*       // value
02126         );
02127   /*
02128   Description:
02129     Begins reading a chunk that must be in the archive at this location.
02130   Parameters:
02131     expected_tcode - [in] chunk's typecode from opennurbs_3dm.h
02132     major_version - [out] 
02133     minor_version - [out] 
02134   Returns:
02135     True if beginning of the chunk was read.  In this case
02136     You must call EndRead3dmChunk(), even if something goes wrong
02137     while you attempt to read the interior of the chunk.
02138     False if the chunk did not exist at the current location in the file.
02139   */
02140   bool BeginRead3dmChunk(
02141         unsigned int expected_tcode,
02142         int* major_version,
02143         int* minor_version
02144         );
02145 
02146   /*
02147   Description:
02148     Calling this will skip rest of stuff in chunk if it was only partially read.
02149   Parameters:
02150     bSupressPartiallyReadChunkWarning - [in]
02151       Generally, a call to ON_WARNING is made when a chunk is partially
02152       read.  If bSupressPartiallyReadChunkWarning is true, then
02153       no warning is issued for partially read chunks.
02154   */
02155   bool EndRead3dmChunk(); 
02156   bool EndRead3dmChunk(bool bSupressPartiallyReadChunkWarning); 
02157 
02158 
02160   //
02161   // Tools for dictionary IO (used in .NET)
02162   //
02163 
02164   /*
02165   Description:
02166     Begins writing a dictionary.
02167   Parameters:
02168     dictionary_id - [in]
02169     version - [in]
02170       It is suggested that you use YYYYMMDD as the version number.
02171     dictionary_name - [in]
02172       You may pass NULL.
02173   Remarks:
02174     Begins a new chunk with tcode TCODE_DICTIONARY and then writes
02175     a TCODE_DICTIONARY_ID chunk containing the id, version and name.
02176     After calling this function, you may either write entries by
02177     calling
02178       BeginWriteDictionaryEntry(); 
02179       write entry definition...
02180       EndWriteDictionaryEntry();
02181     or you may finish writing the dictionay by calling
02182       EndWriteDictionary();
02183   */
02184   bool BeginWriteDictionary(
02185           ON_UUID dictionary_id,
02186           unsigned int version,
02187           const wchar_t* dictionary_name
02188           );
02189   /*
02190   Description:
02191     Begins writing a dictionary entry.
02192   Parameters:
02193     de_type - [in]
02194     entry_name - [in]
02195   Returns:
02196     true 
02197       Entry header was written and you must call EndWriteDictionary()
02198       after writing the entry data.
02199     false 
02200       Failed to write entry header.  Do not call EndWriteDictionary().
02201   Remarks:
02202     Begins a new chunk with tcode TCODE_DICTIONARY_ENTRY,
02203     then writes the int, and then writes the string.
02204   */
02205   bool EndWriteDictionary();
02206 
02207   /*
02208   Description:
02209     Begins writing a dictionary entry.
02210   Parameters:
02211     de_type - [in]
02212     entry_name - [in]
02213   Returns:
02214     true 
02215       Entry header was written and you must call EndWriteDictionary()
02216       after writing the entry data.
02217     false 
02218       Failed to write entry header.  Do not call EndWriteDictionary().
02219   Remarks:
02220     Begins a new chunk with tcode TCODE_DICTIONARY_ENTRY,
02221     then writes the int, and then writes the string.
02222   */
02223   bool BeginWriteDictionaryEntry(
02224           int de_type, 
02225           const wchar_t* entry_name
02226           );
02227   bool EndWriteDictionaryEntry();
02228 
02229   bool BeginReadDictionary(
02230           ON_UUID* dictionary_id,
02231           unsigned int* version,
02232           ON_wString& dictionary_name
02233           );
02234   bool EndReadDictionary();
02235 
02236   /*
02237   Description:
02238     Begin reading a dictionary entry.
02239   Parameters:
02240     de_type - [out]
02241     entry_name - [out]
02242   Returns:
02243     0: serious IO error
02244     1: success
02245         read information and then call EndReadDictionaryEntry()
02246     2: at end of dictionary
02247   */
02248   int BeginReadDictionaryEntry(
02249           int* de_type, 
02250           ON_wString& entry_name
02251           );
02252   bool EndReadDictionaryEntry();
02253 
02254   bool Read3dmGoo( ON_3dmGoo& ); // Call to read "goo"
02255 
02256   // OBSOLETE - Use PeekAt3dmBigChunkType()
02257   ON_DEPRECATED bool PeekAt3dmChunkType( // does not change file position
02258         unsigned int*,   // typecode from opennurbs_3dm.h
02259         int*             // value
02260         );
02261 
02262   bool PeekAt3dmBigChunkType( // does not change file position
02263         ON__UINT32* typecode,
02264         ON__INT64* big_value
02265         );
02266 
02267   bool Seek3dmChunkFromStart( 
02268         // beginning at the start of the active chunk, search portion of
02269         // archive included in active chunk for the start of a subchunk 
02270         // with the specified type.
02271         // if true is returned, then the position is set so the next call to
02272         // BeginRead3dmChunk() will read a chunk with the specified typecode
02273         unsigned int    // typecode from opennurbs_3dm.h
02274         );
02275   bool Seek3dmChunkFromCurrentPosition( 
02276         // beginning at the current position, search portion of archive
02277         // included in active chunk for the start of a subchunk with the
02278         // specified type.
02279         // if true is returned, then the position is set so the next call to
02280         // BeginRead3dmChunk() will read a chunk with the specified typecode
02281         unsigned int    // typecode from opennurbs_3dm.h
02282         );
02283 
02284   // A chunk version is a single byte that encodes a major.minor 
02285   // version number.  Useful when creating I/O code for 3dm chunks
02286   // that may change in the future.  Increment the minor version 
02287   // number if new information is added to the end of the chunk. 
02288   // Increment the major version if the format of the chunk changes
02289   // in some other way.
02290   bool Write3dmChunkVersion(
02291     int, // major // 0 to 15
02292     int  // minor // 0 to 16
02293     );
02294   bool Read3dmChunkVersion(
02295     int*, // major // 0 to 15
02296     int*  // minor // 0 to 16
02297     );
02298 
02299   /*
02300   Description:
02301     Low level tool to writes user data attached to the 
02302     object.  This function should never be called
02303     directly.
02304   Parameters:
02305     object - [in]
02306   Returns:
02307     True if successful.
02308   */
02309   bool WriteObjectUserData( const ON_Object& object );
02310 
02311   /*
02312   Description:
02313     Low level tool to read user data and attach it to
02314     the object.  This function should never be called
02315     directly.
02316   Parameters:
02317     object - [in/out]
02318   Returns:
02319     True if successful.
02320   */
02321   bool ReadObjectUserData( ON_Object& object );
02322 
02323   /*
02324   Description:
02325     If a 3dm archive is being read or written, then this is the
02326     version of the 3dm archive format (1, 2, 3, 4 or 5).
02327   Returns:
02328     @untitle table
02329     0     a 3dm archive is not being read/written
02330     1     a version 1 3dm archive is being read/written
02331     2     a version 2 3dm archive is being read/written
02332     3     a version 3 3dm archive is being read/written
02333     4     a version 4 3dm archive is being read/written
02334     5     an old version 5 3dm archive is being read
02335     50    a version 5 3dm archive is being read/written
02336   See Also:
02337     ON_BinaryArchive::ArchiveOpenNURBSVersion
02338   */
02339   int Archive3dmVersion() const;
02340 
02341   /*
02342   Description:
02343     If a 3dm archive is being read, then this is the version
02344     of openNURBS that was used to write the archive.  This value
02345     is only available after ON_BinaryArchive::Read3dmProperties
02346     is called.
02347   See Also:
02348     ON_BinaryArchive::Archive3dmVersion
02349     ON_BinaryArchive::Read3dmProperties
02350   Returns:
02351     Version of openNURBS used to write the archive.  The openNURBS
02352     version is the value returned by ON::Version.
02353   See Also:
02354     ON::Version
02355     ON_BinaryArchive::Read3dmProperties
02356     ON_BinaryArchive::Archive3dmVersion
02357   Remarks:
02358     This value is rarely needed.  You probably want to
02359     use ON_BinaryArchive::Archive3dmVersion.
02360   */
02361   int ArchiveOpenNURBSVersion() const;
02362 
02363   /*
02364   Description:
02365     When a 3dm archive is saved from an MFC application that
02366     supports Windows linking/embedding, the first 5kb to 1mb
02367     of the file contains information that is put there by MFC.
02368     ArchiveStartOffset() returns the offset into the file where
02369     the 3dm archive actually begins. The call to 
02370     ON_BinaryArchive::Read3dmStartSection() calculates this
02371     offset and stores the value in m_3dm_start_section_offset.
02372   Returns:
02373     Offset into the binary "file" where the actual 3dm archive
02374     begins.
02375   Remarks:
02376     Generally, this value can be ignored. This function is
02377     a diagnostice tool that is used to analyzed damaged files.
02378   */
02379   size_t ArchiveStartOffset() const;
02380 
02381   enum table_type
02382   {
02383     no_active_table = 0,
02384     properties_table,
02385     settings_table,
02386     bitmap_table,
02387     texture_mapping_table,
02388     material_table,
02389     linetype_table,
02390     layer_table,
02391     light_table,
02392     object_table,
02393     group_table,
02394     font_table,
02395     dimstyle_table,
02396     hatchpattern_table,
02397     instance_definition_table,
02398     historyrecord_table,
02399     user_table
02400   };
02401 
02402   /*
02403   Description:
02404     Expert user function for reading damaged files.
02405   Parameters:
02406     chunk - [out] current chunk.
02407   Returns:
02408     Level of the chunk or 0 if there is no current
02409     chunk.
02410   */
02411   int GetCurrentChunk(ON_3DM_CHUNK& chunk) const;
02412   int GetCurrentChunk(ON_3DM_BIG_CHUNK& big_chunk) const;
02413 
02414   /*
02415   Description:
02416     Expert user function for reading damaged files.  The search starts
02417     at the beginning of the file.
02418   Parameters:
02419     tcode_table - [in] typecode of the table
02420     tcode_record - [in] typecode of the record
02421     class_uuid - [in] id of the opennurbs class in the record
02422     min_length_data - [in] minimum size of the opennurbs class data
02423   Returns:
02424     True if the table start is found.  In this case the current
02425     position of the archive is at the start of the table and
02426     the standared BeginRead3dm...Table() function can be used.
02427     False if the table start is not found.
02428   */
02429   bool FindTableInDamagedArchive(
02430           unsigned int tcode_table,
02431           unsigned int tcode_record,
02432           ON_UUID class_uuid,
02433           int min_length_data
02434           );
02435 
02436   /*
02437   Description:
02438     Expert user function for studying contents of a file.
02439     The primary use is as an aid to help dig through files
02440     that have been damaged (bad disks, transmission errors, etc.)
02441     If an error is found, a line that begins with the word
02442     "ERROR" is printed.
02443   Parameters:
02444     text_log - [in] place to print informtion
02445     recursion_depth - [in] simply a counter
02446         to aid in debugging.
02447   Returns:
02448     0 if something went wrong, otherwise the typecode
02449     of the chunk that was just studied.
02450   */
02451   unsigned int 
02452   Dump3dmChunk(
02453         ON_TextLog& text_log, 
02454         int recursion_depth = 0
02455         );
02456 
02457 protected:
02458 
02459   /*
02460   Description:
02461     Works like the C runtrim fread().
02462   Returns:
02463     actual number of bytes read (like fread())
02464   */
02465   virtual
02466   size_t Read( size_t, void* ) = 0; 
02467 
02468   /*
02469   Description:
02470     Works like the C runtrim fwrite().
02471   Returns:
02472     actual number of bytes written (like fwrite())
02473   */
02474   virtual
02475   size_t Write( size_t, const void* ) = 0;
02476 
02477   /*
02478   Description:
02479     Force Write() to flush any buffered data to physical archive.
02480   Returns:
02481     True if succesful or if there is nothing to flush.  False if
02482     information could not be flushed.
02483   */
02484   virtual
02485   bool Flush() = 0;
02486 
02487   /*
02488   Description:
02489     When ON_BinaryArchive::ReadObject() encounters userdata and
02490     the user data class id is not present,  LoadUserDataApplication
02491     is called to load the application that created user data.
02492   Returns:
02493     0 - could not load the application
02494     1 - successfully loaded the application
02495     2 - the application was already loaded
02496   */
02497   virtual
02498   int LoadUserDataApplication( 
02499     ON_UUID application_id 
02500     );
02501 
02502   bool SetArchive3dmVersion(int);
02503 
02504 private:
02505   // 16 bit integer IO
02506   bool WriteInt8( size_t, const ON__INT8* );
02507   bool ReadInt8( size_t, ON__INT8* );
02508 
02509   // 16 bit integer IO
02510   bool WriteInt16( size_t, const ON__INT16* );
02511   bool ReadInt16( size_t, ON__INT16* );
02512 
02513   // 32 bit integer IO
02514   bool WriteInt32( size_t, const ON__INT32* );
02515   bool ReadInt32( size_t, ON__INT32* );
02516 
02517   // 64 bit integer IO
02518   bool WriteInt64( size_t, const ON__INT64* );
02519   bool ReadInt64(  size_t, ON__INT64* );
02520 
02521   bool BeginWrite3dmTable( 
02522     unsigned int // tcode
02523     );
02524   bool EndWrite3dmTable( 
02525     unsigned int // tcode
02526     );
02527   bool BeginRead3dmTable( 
02528     unsigned int // tcode
02529     );
02530   bool EndRead3dmTable( 
02531     unsigned int // tcode
02532     );
02533   
02534   bool Read3dmV1Layer( ON_Layer*& );
02535   int  Read3dmV1Light(  // returns 0 at end of light table
02536                       //         1 light successfully read
02537                       //        -1 if file is corrupt
02538             ON_Light**, // light returned here
02539             ON_3dmObjectAttributes* // optional - if NOT NULL, object attributes are
02540                                     //            returned here
02541             );
02542   int Read3dmV1Material( ON_Material** );
02543   int  Read3dmV1Object( // returns 0 at end of object table
02544                       //         1 if object is read
02545                       //         2 if object is skipped because it does not match filter
02546                       //        -1 if file is corrupt
02547           ON_Object**, // object returned here (NULL if skipped)
02548           ON_3dmObjectAttributes*, // optional - if NOT NULL, object attributes are
02549                                    //            returned here
02550           unsigned int = 0 // optional filter made by setting ON::object_type bits
02551           );  // returns NULL at end of object table
02552 
02553   bool Read3dmV1AttributesOrMaterial( 
02554             ON_3dmObjectAttributes*,    // attributes,
02555             ON_Material*,      // material,
02556             ON_BOOL32&,             // bHaveMat
02557             unsigned int,      // end_mark_tcode 
02558             class ON__3dmV1_XDATA* = 0 // v1 "xdata"
02559             );
02560   bool Read3dmV1String( ON_String& );
02561   int  Read3dmV1LayerIndex( const char* ) const;
02562 
02563 public:
02564   // helpers for reading V1 objects
02565   bool ReadV1_TCODE_RH_POINT(ON_Object**,ON_3dmObjectAttributes*);
02566   bool ReadV1_TCODE_MESH_OBJECT(ON_Object**,ON_3dmObjectAttributes*);
02567   bool ReadV1_TCODE_LEGACY_CRV(ON_Object**,ON_3dmObjectAttributes*);
02568   bool ReadV1_TCODE_LEGACY_FAC(ON_Object**,ON_3dmObjectAttributes*);
02569   bool ReadV1_TCODE_LEGACY_SHL(ON_Object**,ON_3dmObjectAttributes*);
02570   bool ReadV1_TCODE_RHINOIO_OBJECT_NURBS_CURVE(ON_Object**,ON_3dmObjectAttributes*);
02571   bool ReadV1_TCODE_RHINOIO_OBJECT_NURBS_SURFACE(ON_Object**,ON_3dmObjectAttributes*);
02572   bool ReadV1_TCODE_RHINOIO_OBJECT_BREP(ON_Object**,ON_3dmObjectAttributes*);
02573   bool ReadV1_TCODE_ANNOTATION(unsigned int,ON_Object**,ON_3dmObjectAttributes*);
02574 
02575 private:
02576   ON::archive_mode Mode() const; // current read/write mode
02577   void UpdateCRC( size_t, const void* );
02578   int ReadObjectHelper(ON_Object**);
02579 
02580   int m_3dm_version;
02581   int m_3dm_v1_layer_index;
02582   int m_3dm_v1_material_index;
02583 
02584   // The bits in m_error_message_mask are used to mask errors
02585   // when we know we are doing something that may generate an
02586   // error.
02587   //
02588   // bit 0x00000001
02589   //   V1 files do not have a table structure and are read using
02590   //   multiple passes and there are valid situations where a 
02591   //   4 byte read is attempted at the end of a file.
02592   //
02593   // bit 0x00000002
02594   //   Some v1 files do not have an end mark.  When reading
02595   //   these v1 files bit 0x02 is set.
02596   //
02597   // bit 0x00000004
02598   //   Requested read may go beyond end of file.
02599   //   One situation where this happens is when a table is not at the 
02600   //   expected location in a file, 
02601 
02602   unsigned int m_error_message_mask;
02603 protected:
02604   unsigned int ErrorMessageMask() const;
02605   /*
02606   Paramters:
02607     sizeof_request - [in] 
02608       value of count parameter passed to virtual Read() function.
02609     sizeof_read - [in]
02610       number of bytes actually read by the virtual Read() function.
02611   Returns:
02612     True if a call to Read() is permitted to ask for more bytes
02613     than are left in the file.  This value varies as the file
02614     is read and must be checked at each failure.
02615   */
02616   bool MaskReadError( ON__UINT64 sizeof_request, ON__UINT64 sizeof_read ) const;
02617 private:
02618 
02619 
02620   // When a 3DM archive is read, m_3dm_opennurbs_version records the version of
02621   // OpenNURBS used to create the archive.  Otherwise, m_3dm_opennurbs_version
02622   // is zero.
02623   //
02624   // Read3dmProperties() sets this to the version of OpenNURBS that was
02625   // used to write file file.  If the file was created using a version
02626   // of OpenNURBS before 200012210, this number will be zero.
02627   //
02628   // Write3dmProperties() stores the value returned by ON::Version() in
02629   // the archive's properties table.
02630   friend void ON_SetBinaryArchiveOpenNURBSVersion(ON_BinaryArchive&,int);
02631   int m_3dm_opennurbs_version;
02632 
02633   // When a 3dm archive is saved from an MFC application that supports
02634   // Windows linking/embedding, the first 5kb to 1mb of the file contains
02635   // information that is put there by MFC.  m_3dm_start_section_offset
02636   // records the offset into the file where the 3dm archive actually begins.
02637   size_t m_3dm_start_section_offset;
02638 
02639   table_type m_active_table;
02640 
02641   table_type TableTypeFromTypecode( unsigned int ); // table type from tcode
02642 
02643   ON_SimpleArray<ON_3DM_BIG_CHUNK> m_chunk;
02644 
02645   // stack of chunks
02646   bool PushBigChunk( ON__UINT32 typecode, ON__INT64 value );
02647 
02648   bool WriteChunkTypecode( ON__UINT32 );
02649   bool ReadChunkTypecode( ON__UINT32* );
02650   bool WriteChunkValue( ON__UINT32 typecode, ON__INT64 );
02651   bool WriteChunkLength( ON__UINT64 );
02652   bool ReadChunkValue( ON__UINT32 typecode, ON__INT64* value64 );
02653   bool FindMisplacedTable( 
02654         ON__UINT64 filelength,
02655         const ON__UINT32 table_tocde,
02656         const ON__UINT32 table_record_record,
02657         const ON_UUID class_uuid,
02658         const ON__UINT64 min_length_data
02659         );
02660 
02661   bool ReadObjectUserDataAnonymousChunk(
02662           const ON__UINT64 length_TCODE_ANONYMOUS_CHUNK,
02663           const int archive_3dm_version,
02664           const int archive_opennurbs_version,
02665           class ON_UserData* ud );
02666 
02667 public:
02668   size_t SizeofChunkLength() const;
02669 
02670 private:
02671   bool WriteEOFSizeOfFile( ON__UINT64 );
02672   bool ReadEOFSizeOfFile( ON__UINT64* );
02673 
02674   bool m_bDoChunkCRC; // true if active chunk crc status should be checked
02675                       // and updated.
02676   int m_bad_CRC_count; // number of chunks that have a bad crc
02677 
02678 
02679 private:
02680   // compressed buffer I/O uses zlib 1.1.3 inflate()/deflate()
02681   struct
02682   {
02683     ON::archive_mode mode; // ON::read = read and inflate,  ON::write = deflate and write
02684     enum
02685     {
02686       sizeof_x_buffer = 16384
02687     };
02688     unsigned char    buffer[sizeof_x_buffer];
02689     z_stream         strm;
02690   } m_zlib;
02691 
02692   // returns number of bytes written
02693   size_t WriteDeflate(
02694         size_t,         // sizeof uncompressed input data
02695         const void*  // uncompressed input data
02696         );
02697   bool ReadInflate(
02698         size_t,  // sizeof uncompressed input data
02699         void* // buffer to hold uncompressed data
02700         );
02701   bool CompressionInit();
02702   void CompressionEnd();
02703 
02704 private:
02705   // endian-ness of the cpu reading this file.
02706   // 3dm files are alwasy saved with little endian byte order.
02707   ON::endian m_endian;
02708 
02709   ON::archive_mode m_mode;
02710 
02711   // 3dm write options
02712   bool m_bSaveUserData; // true to save user data (increases file size)
02713   bool m_bSavePreviewImage;    // true to save 200x200 preview bitmap (increases file size)
02714   bool m_bEmbedTextureBitmaps; // true to embed texture, bump, trace, and wallpaper bitmaps (increases file size)
02715   bool m_bSaveRenderMeshes;    // true to save meshes used to render B-rep objects (increases file size)
02716   bool m_bSaveAnalysisMeshes;  // true to save meshes used in surface analysis (increases file size)
02717 
02718   // ids of plug-ins that support saving older (V3) versions
02719   // of user data.  This information is filled in from the
02720   // list of plug-ins passed in whenteh settings are saved.
02721   ON_SimpleArray< ON_UUID > m_V3_plugin_id_list;
02722 
02723   struct ON__3dmV1LayerIndex* m_V1_layer_list;
02724 
02725   // prohibit default construction, copy construction, and operator=
02726   ON_BinaryArchive();
02727   ON_BinaryArchive( const ON_BinaryArchive& ); // no implementation
02728   ON_BinaryArchive& operator=( const ON_BinaryArchive& ); // no implementation
02729 
02730 };
02731 
02732 class ON_CLASS ON_3dmGoo
02733 {
02734   // used to store goo
02735 public:
02736   ON_3dmGoo();
02737   ~ON_3dmGoo();
02738   ON_3dmGoo( const ON_3dmGoo& );
02739   ON_3dmGoo& operator=( const ON_3dmGoo& );
02740 
02741   void Dump(ON_TextLog&) const;
02742 
02743   unsigned int m_typecode;
02744   int m_value;
02745   unsigned char* m_goo;
02746   ON_3dmGoo* m_next_goo;
02747   ON_3dmGoo* m_prev_goo;
02748 };
02749 
02750 
02751 class ON_CLASS ON_BinaryFile : public ON_BinaryArchive
02752 {
02753 public:
02754   ON_BinaryFile( ON::archive_mode );
02755 
02756   /*
02757   Description:
02758     Create an ON_BinaryArchive that reads/writes from an ordinary file.
02759   Parameters:
02760     mode - [in]
02761     fp - [in]
02762       If a file is being read, fp is the pointer returned 
02763       from ON_FileStream::Open(...,"rb").
02764       If a file is being written, fp is the pointer returned 
02765       from ON_FileStream::Open(...,"wb").
02766   */
02767   ON_BinaryFile( ON::archive_mode, FILE* fp );
02768 
02769   virtual ~ON_BinaryFile();
02770 
02771   // ON_BinaryArchive overrides
02772   size_t CurrentPosition() const; 
02773   bool SeekFromCurrentPosition(int);
02774   bool SeekFromStart(size_t);
02775   bool AtEnd() const;
02776 
02777   // fseek from end (since the file has an end)
02778   bool SeekFromEnd( int ); 
02779 
02781   // To use custom memory buffering instead of relying
02782   // on fread()/fwrite()'s build in buffering, call
02783   // EnableMemoryBuffer() with the buffer size immediately
02784   // after constructing the ON_BinaryFile.  There appear
02785   // to be enough bugs in existing Windows NT/2000 NETWORK
02786   // I/O that using this hack will speed up I/O by factors
02787   // of 10 to 100.
02788   void EnableMemoryBuffer(
02789          int=16384 // capacity of memory buffer
02790          );
02791 
02792 protected:
02793   size_t Read( size_t, void* );
02794   size_t Write( size_t, const void* );
02795   bool Flush();
02796 
02797 private:
02798   // Implementation
02799   FILE* m_fp;
02800 
02801   // if m_memory_buffer_capacity is zero, then Write() uses
02802   // fwrite() directly.  If m_memory_buffer_capacity is
02803   // greater than zero, then Write() buffers its results
02804   // into m_memory_buffer.  This is provided to work around
02805   // bugs in some networks that result in extremely slow
02806   // performance when seeking is used.
02807   size_t m_memory_buffer_capacity;
02808   size_t m_memory_buffer_size;
02809   size_t m_memory_buffer_ptr;
02810   unsigned char* m_memory_buffer;
02811 
02812 private:
02813   // prohibit default construction, copy construction, and operator=
02814   ON_BinaryFile( ); // no implementation
02815   ON_BinaryFile( const ON_BinaryFile& ); // no implementation
02816   ON_BinaryFile& operator=( const ON_BinaryFile& ); // no implementation
02817 };
02818 
02819 class ON_CLASS ON_BinaryArchiveBuffer : public ON_BinaryArchive
02820 {
02821 public:
02822   /*
02823   Description:
02824     Create an ON_BinaryArchive that reads/writes from an ON_Buffer.
02825   Parameters:
02826     mode - [in]
02827     buffer - [in]
02828   Remarks:
02829     If a non-null buffer is specifed, then do not call SetBuffer()
02830   */
02831   ON_BinaryArchiveBuffer( ON::archive_mode, ON_Buffer* buffer );
02832 
02833   virtual ~ON_BinaryArchiveBuffer();
02834 
02835   /*
02836   Description:
02837     If the ON_BinaryArchiveBuffer class is created with the constructor
02838     that has a single "mode" parameter, then use SetBuffer()
02839     to specify the buffer to read/write from before using
02840     the ON_BinaryArchiveBuffer.
02841   Parameters:
02842     buffer - [in]
02843   Returns:
02844     True if the buffer is set.  Once the buffer is set it
02845     cannot be changed.
02846   */
02847   bool SetBuffer( ON_Buffer* buffer );
02848 
02849   /*
02850   Returns:
02851     Buffer being read/written. 
02852   */
02853   ON_Buffer* Buffer() const;
02854 
02855   // virtual ON_BinaryArchive overrides
02856   size_t CurrentPosition() const; 
02857   bool SeekFromCurrentPosition(int);
02858   bool SeekFromStart(size_t);
02859   bool AtEnd() const;
02860 
02861   bool SeekFromEnd( ON__INT64 ); 
02862 
02863 protected:
02864   size_t Read( size_t, void* );
02865   size_t Write( size_t, const void* );
02866   bool Flush();
02867 
02868 private:
02869   // Buffer being read/written.
02870   ON_Buffer* m_buffer;
02871 
02872 private:
02873   // prohibit use - you should specify a buffer.
02874   ON_BinaryArchiveBuffer( ON::archive_mode );
02875 private:
02876   // prohibit default construction, copy construction, and operator=
02877   ON_BinaryArchiveBuffer( ); // no implementation
02878   ON_BinaryArchiveBuffer( const ON_BinaryArchiveBuffer& ); // no implementation
02879   ON_BinaryArchiveBuffer& operator=( const ON_BinaryArchiveBuffer& ); // no implementation
02880 };
02881 
02882 
02883 class ON_CLASS ON_Read3dmBufferArchive : public ON_BinaryArchive
02884 {
02885 public:
02886 
02887   /*
02888   Description:
02889     Construct an ON_BinaryArchive for reading information from a memory buffer.
02890   Parameters:
02891     sizeof_buffer - [in] size of buffer in bytes (>0)
02892     buffer - [in] memory buffer containing binary archive
02893     bCopyBuffer - [in]
02894       true - copy the input buffer.  
02895           Useful when the buffer may be destroyed while this class is still in use.
02896       false - Do not copy the input buffer.  
02897           In this case you are responsible for making certain the input buffer 
02898           is valid while this class is in use.
02899     archive_3dm_version  - [in] (1,2,3,4 or 5)
02900     archive_opennurbs_version - [in] YYYYMMDDn
02901   */
02902   ON_Read3dmBufferArchive( 
02903     size_t sizeof_buffer, 
02904     const void* buffer,
02905     bool bCopyBuffer,
02906     int archive_3dm_version,
02907     int archive_opennurbs_version
02908     );
02909 
02910   ~ON_Read3dmBufferArchive();
02911 
02912   /*
02913   Returns: 
02914      value of m_sizeof_buffer
02915   */
02916   size_t SizeOfBuffer() const;
02917 
02918   /*
02919   Returns: 
02920      value of m_buffer
02921   */
02922   const void* Buffer() const;
02923 
02924   // ON_BinaryArchive overrides
02925   size_t CurrentPosition() const; 
02926   bool SeekFromCurrentPosition(int); 
02927   bool SeekFromStart(size_t);
02928   bool AtEnd() const;
02929 
02930 protected:
02931   // ON_BinaryArchive overrides
02932   size_t Read( size_t, void* ); // return actual number of bytes read (like fread())
02933   size_t Write( size_t, const void* );
02934   bool Flush();
02935 
02936 private:
02937   void* m_p;
02938   const unsigned char* m_buffer;
02939   size_t m_sizeof_buffer;
02940   size_t m_buffer_position;
02941   ON__INT_PTR m_reserved1;
02942   ON__INT_PTR m_reserved2;
02943   ON__INT_PTR m_reserved3;
02944   ON__INT_PTR m_reserved4;
02945 
02946 private:
02947   // prohibit use - no implementation
02948   ON_Read3dmBufferArchive(); 
02949   ON_Read3dmBufferArchive( const ON_Read3dmBufferArchive& );
02950   ON_Read3dmBufferArchive& operator=(const ON_Read3dmBufferArchive&);
02951 };
02952 
02953 class ON_CLASS ON_Write3dmBufferArchive : public ON_BinaryArchive
02954 {
02955 public:
02956 
02957   /*
02958   Description:
02959     Construct an ON_BinaryArchive for writing information to a memory buffer.
02960   Parameters:
02961     initial_sizeof_buffer - [in] 
02962       initial size of buffer in bytes (>=0)
02963       If you are unable to estimate the size you will need, pass in zero.
02964     max_sizeof_buffer - [in] 
02965       maximum size of buffer in bytes (>=0)
02966       If max_sizeof_buffer > 0 and the amount of information saved 
02967       requires a buffer larger than this size, then writing fails. 
02968       If max_sizeof_buffer <= 0, then no buffer size limits are enforced.
02969     archive_3dm_version  - [in] (0, ,2,3,4 or 50)
02970       Pass 0 or ON_BinaryArchive::CurrentArchiveVersion() to write the
02971       version of opennurbs archives used by lastest version of Rhino.
02972     archive_opennurbs_version - [in] YYYYMMDDn
02973   */
02974   ON_Write3dmBufferArchive( 
02975     size_t initial_sizeof_buffer, 
02976     size_t max_sizeof_buffer, 
02977     int archive_3dm_version,
02978     int archive_opennurbs_version
02979     );
02980 
02981   ~ON_Write3dmBufferArchive();
02982 
02983   /*
02984   Returns: 
02985      Size of the archive in bytes.
02986   */
02987   size_t SizeOfArchive() const;
02988 
02989   /*
02990   Returns: 
02991      value of m_sizeof_buffer
02992   */
02993   size_t SizeOfBuffer() const;
02994 
02995   /*
02996   Returns: 
02997      value of m_buffer.
02998      SizeOfArchive() reports the number of bytes
02999      written to this buffer.
03000      SizeOfBuffer() reports the number of bytes
03001      allocated in this buffer.
03002      
03003   */
03004   const void* Buffer() const;
03005 
03006   /*
03007   Returns:
03008     The pointer to the buffer and sets all 
03009     members on this archive back to zero.
03010     The caller is responsible for calling onfree() on
03011     the pointer when finished with the buffer.
03012   */
03013   void* HarvestBuffer();
03014 
03015   // ON_BinaryArchive overrides
03016   size_t CurrentPosition() const; 
03017   bool SeekFromCurrentPosition(int); 
03018   bool SeekFromStart(size_t);
03019   bool AtEnd() const;
03020 
03021 protected:
03022   // ON_BinaryArchive overrides
03023   size_t Read( size_t, void* ); 
03024   size_t Write( size_t, const void* ); // return actual number of bytes written (like fwrite())
03025   bool Flush();
03026 
03027 private:
03028   void AllocBuffer(size_t);
03029   void* m_p;
03030   unsigned char* m_buffer;
03031   size_t m_sizeof_buffer;
03032   const size_t m_max_sizeof_buffer;
03033   size_t m_sizeof_archive;
03034   size_t m_buffer_position;
03035   ON__INT_PTR m_reserved1;
03036   ON__INT_PTR m_reserved2;
03037   ON__INT_PTR m_reserved3;
03038   ON__INT_PTR m_reserved4;
03039 
03040 private:
03041   // prohibit use - no implementation
03042   ON_Write3dmBufferArchive(); 
03043   ON_Write3dmBufferArchive( const ON_Write3dmBufferArchive& );
03044   ON_Write3dmBufferArchive& operator=(const ON_Write3dmBufferArchive&);
03045 };
03046 
03047 /*
03048 Description:
03049   Create a simple archive that contains a single geometric object.
03050 Parameters:
03051   archive - [in] destination archive.
03052   version - [in] (0, 2, 3, 4, or 50) format version.archive version number.
03053       Version 2 format can be read by Rhino 2 and Rhino 3.  Version
03054       3 format can be read by Rhino 3.
03055       Pass 0 or ON_BinaryArchive::CurrentArchiveVersion() to write
03056       the latest version of archives supported by Rhino.
03057   object - [in] object to be saved in the archive's object table.
03058       This is typically some type of ON_Curve, ON_Surface, ON_Mesh,
03059       or ON_Brep.
03060 Returns:
03061   @untitled table
03062   true     archive successfully written.
03063   false    archive not successfully written.
03064 Example:
03065 
03066           const char* filename = "myfile.3dm";
03067           FILE* fp = ON::OpenFile( filename, "wb" );
03068           ON_BinaryFile file( fp, ON::write3dm );
03069           ON_BOOL32 ok = ON_WriteArchive( archive, geometry );
03070           ON::CloseFile( fp );
03071 
03072 Remarks:
03073   The object table in the archive will contain a single
03074   object.
03075 */
03076 ON_DECL
03077 bool ON_WriteOneObjectArchive( 
03078           ON_BinaryArchive& archive,
03079           int version,
03080           const ON_Object& object
03081           );
03082 
03083 #endif
03084 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:59