1 : /******************************************************************************
2 : *
3 : * Purpose: Declaration of the CPCIDSKSegment class.
4 : *
5 : ******************************************************************************
6 : * Copyright (c) 2009
7 : * PCI Geomatics, 50 West Wilmot Street, Richmond Hill, Ont, 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 );
60 : void LoadSegmentHeader();
61 :
62 180 : PCIDSKBuffer &GetHeader() { return header; }
63 : void FlushHeader();
64 :
65 : void WriteToFile( const void *buffer, uint64 offset, uint64 size );
66 : void ReadFromFile( void *buffer, uint64 offset, uint64 size );
67 :
68 0 : eSegType GetSegmentType() { return segment_type; }
69 54 : std::string GetName() { return segment_name; }
70 : std::string GetDescription();
71 58 : int GetSegmentNumber() { return segment; }
72 30 : uint64 GetContentSize() { return data_size - 1024; }
73 : bool IsAtEOF();
74 :
75 : void SetDescription( const std::string &description);
76 :
77 : std::string GetMetadataValue( const std::string &key ) const;
78 : void SetMetadataValue( const std::string &key, const std::string &value );
79 : std::vector<std::string> GetMetadataKeys() const;
80 :
81 224 : virtual void Synchronize() {}
82 :
83 : std::vector<std::string> GetHistoryEntries() const;
84 : void SetHistoryEntries( const std::vector<std::string> &entries );
85 : void PushHistory(const std::string &app,
86 : const std::string &message);
87 :
88 0 : virtual std::string ConsistencyCheck() { return ""; }
89 :
90 : protected:
91 : PCIDSKFile *file;
92 :
93 : int segment;
94 :
95 : eSegType segment_type;
96 : char segment_flag;
97 : std::string segment_name;
98 :
99 : uint64 data_offset; // includes 1024 byte segment header.
100 : uint64 data_size;
101 :
102 : PCIDSKBuffer header;
103 :
104 : mutable MetadataSet *metadata;
105 :
106 : std::vector<std::string> history_;
107 :
108 : void MoveData( uint64 src_offset, uint64 dst_offset,
109 : uint64 size_in_bytes );
110 : };
111 :
112 : } // end namespace PCIDSK
113 : #endif // _INCLUDE_SEGMENT_PCIDSKSEGMENT_H
|