Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Purpose: Declaration of the CPCIDSKSegment class. 4 : * 5 : ****************************************************************************** 6 : * Copyright (c) 2009 7 : * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada. 8 : * 9 : * Permission is hereby granted, free of charge, to any person obtaining a 10 : * copy of this software and associated documentation files (the "Software"), 11 : * to deal in the Software without restriction, including without limitation 12 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 : * and/or sell copies of the Software, and to permit persons to whom the 14 : * Software is furnished to do so, subject to the following conditions: 15 : * 16 : * The above copyright notice and this permission notice shall be included 17 : * in all copies or substantial portions of the Software. 18 : * 19 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 : * DEALINGS IN THE SOFTWARE. 26 : ****************************************************************************/ 27 : 28 : #ifndef INCLUDE_SEGMENT_PCIDSKSEGMENT_H 29 : #define INCLUDE_SEGMENT_PCIDSKSEGMENT_H 30 : 31 : #include "pcidsk_config.h" 32 : #include "pcidsk_types.h" 33 : #include "pcidsk_buffer.h" 34 : #include "pcidsk_segment.h" 35 : 36 : #include <string> 37 : #include <vector> 38 : 39 : namespace PCIDSK 40 : { 41 : class PCIDSKFile; 42 : class MetadataSet; 43 : 44 : /************************************************************************/ 45 : /* CPCIDSKSegment */ 46 : /* */ 47 : /* Base class for accessing all segments. Provides core */ 48 : /* PCIDSKObject implementation for segments with raw segment io */ 49 : /* options. */ 50 : /************************************************************************/ 51 : 52 : class CPCIDSKSegment : virtual public PCIDSKSegment 53 : { 54 : public: 55 : CPCIDSKSegment( PCIDSKFile *file, int segment, 56 : const char *segment_pointer ); 57 : virtual ~CPCIDSKSegment(); 58 : 59 : void LoadSegmentPointer( const char *segment_pointer ) override final; 60 : void LoadSegmentHeader(); 61 : 62 5699 : PCIDSKBuffer &GetHeader() { return header; } 63 : void FlushHeader(); 64 : 65 : void WriteToFile( const void *buffer, uint64 offset, uint64 size ) override; 66 : void ReadFromFile( void *buffer, uint64 offset, uint64 size ) override; 67 : 68 0 : eSegType GetSegmentType() override { return segment_type; } 69 1183 : std::string GetName() override { return segment_name; } 70 : std::string GetDescription() override; 71 96 : int GetSegmentNumber() override { return segment; } 72 0 : bool IsContentSizeValid() const override { return data_size >= 1024; } 73 142 : uint64 GetContentSize() override { return data_size - 1024; } 74 46 : uint64 GetContentOffset() override { return data_offset; } 75 : bool IsAtEOF() override; 76 : bool CanExtend(uint64 size) const override; 77 : 78 : void SetDescription( const std::string &description) override; 79 : 80 : std::string GetMetadataValue( const std::string &key ) const override; 81 : void SetMetadataValue( const std::string &key, const std::string &value ) override; 82 : std::vector<std::string> GetMetadataKeys() const override; 83 : 84 241 : virtual void Synchronize() override {} 85 : 86 : std::vector<std::string> GetHistoryEntries() const override; 87 : void SetHistoryEntries( const std::vector<std::string> &entries ) override; 88 : void PushHistory(const std::string &app, 89 : const std::string &message) override; 90 : 91 0 : virtual std::string ConsistencyCheck() override { return ""; } 92 : 93 : protected: 94 : PCIDSKFile *file; 95 : 96 : int segment; 97 : 98 : eSegType segment_type; 99 : char segment_flag; 100 : std::string segment_name; 101 : 102 : uint64 data_offset; // includes 1024 byte segment header. 103 : uint64 data_size; 104 : uint64 data_size_limit; 105 : 106 : PCIDSKBuffer header; 107 : 108 : mutable MetadataSet *metadata; 109 : 110 : std::vector<std::string> history_; 111 : 112 : void MoveData( uint64 src_offset, uint64 dst_offset, 113 : uint64 size_in_bytes ); 114 : }; 115 : 116 : } // end namespace PCIDSK 117 : #endif // INCLUDE_SEGMENT_PCIDSKSEGMENT_H