1 //
2 // This file is part of the SDTS++ toolkit, written by the U.S.
3 // Geological Survey.  It is experimental software, written to support
4 // USGS research and cartographic data production.
5 //
6 // SDTS++ is public domain software.  It may be freely copied,
7 // distributed, and modified.  The USGS welcomes user feedback, but makes
8 // no committment to any level of support for this code.  See the SDTS
9 // web site at http://mcmcweb.er.usgs.gov/sdts for more information,
10 // including points of contact.
11 //
12 //
13 // sio_8211Record.h
14 //
15 
16 
17 #ifndef INCLUDED_SIO_8211RECORD_H
18 #define INCLUDED_SIO_8211RECORD_H
19 
20 #include <iostream>
21 
22 
23 
24 #ifndef INCLUDED_SIO_8211DIRECTORY_H
25 #include <sdts++/io/sio_8211Directory.h>
26 #endif
27 
28 #ifndef INCLUDED_SIO_8211FIELDAREA_H
29 #include <sdts++/io/sio_8211FieldArea.h>
30 #endif
31 
32 #ifndef INCLUDED_SIO_8211LEADER_H
33 #include <sdts++/io/sio_8211Leader.h>
34 #endif
35 
36 
37 class sio_8211Field;
38 class sio_Buffer;
39 
40 
41 
42 /// Abstract class. Represents the commonality between a DDR and a DR.
43 class sio_8211Record
44 {
45    public:
46 
47       ///
48       sio_8211Record();
49 
50       ///
51       sio_8211Record( sio_8211Record const & );
52 
53       ///
54       sio_8211Record& operator=( sio_8211Record const & );
55 
56       ///
57       virtual ~sio_8211Record();
58 
59       /**
60        Pure virtual because child classes define their own leaders.  That
61        is, sio_8211DR has an sio_8211DRLeader and an sio_8211DDR has an
62        sio_8211DDRLeader.
63       */
64       virtual sio_8211Leader const& getLeader() const = 0;
65 
66       ///
67       sio_8211Directory const& getDirectory() const;
68 
69       ///
70       sio_8211FieldArea const& getFieldArea() const;
71 
72       /// Add a field to the record that has the given tag.
73       bool addField(std::string const & tag, sio_8211Field const& field);
74 
75       ///
76       bool addField(std::string const & tag, sio_Buffer const& field_data);
77 
78       friend std::istream& operator>>(std::istream& istr, sio_8211Record& record);
79       friend std::ostream& operator<<(std::ostream& ostr, sio_8211Record const & record);
80 
81    protected:
82 
83       ///
84       virtual std::istream& streamExtract(std::istream& istr) = 0;
85 
86       ///
87       virtual std::ostream& streamInsert(std::ostream& ostr) const;
88 
89       ///
90       virtual void setLeader( sio_8211Leader const& );
91 
92       ///
93       void setDirectory( sio_8211Directory const& );
94 
95       ///
96       void setFieldArea( sio_8211FieldArea const& );
97 
98       /// non-const version for streamExtract()
99       sio_8211Directory& getDirectory_();
100 
101       ///
102       sio_8211FieldArea& getFieldArea_();
103 
104       ///
105       virtual sio_8211Leader& getLeader_() = 0;
106 
107       /**
108        Utility for making sure that the given leader accurately
109        reflects the current state of the record.  That is, the
110        various lengths are all updated appropriately.
111       */
112       virtual void synchLeaderWithRecord_( );
113 
114    private:
115 
116       ///
117       sio_8211Directory    dir_;
118 
119       ///
120       sio_8211FieldArea    fieldArea_;
121 
122 }; // class sio_8211Record
123 
124 
125 ///
126 std::istream&
127 operator>>(std::istream& istr, sio_8211Record& record);
128 
129 ///
130 std::ostream&
131 operator<<(std::ostream& ostr, sio_8211Record const & record);
132 
133 #endif  // INCLUDED_SIO_8211RECORD_H
134