OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRpfLocationSection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 // Description: Rpf support class
10 //
11 //********************************************************************
12 // $Id: ossimRpfLocationSection.cpp 20324 2011-12-06 22:25:23Z dburken $
13 
15 #include <ossim/base/ossimCommon.h> /* ossim::byteOrder() */
16 #include <ossim/base/ossimEndian.h>
18 #include <ossim/base/ossimTrace.h>
20 #include <istream>
21 #include <ostream>
22 #include <iterator>
23 
24 static const ossimTrace traceDebug("ossimRpfLocationSection:debug");
25 
27 {
28  return data.print(out);
29 }
30 
32  : m_componentId(0),
33  m_componentLength(0),
34  m_componentLocation(0)
35 {
36 }
37 
39  const ossimRpfComponentLocationRecord& record)
40  : m_componentId(record.m_componentId),
41  m_componentLength(record.m_componentLength),
42  m_componentLocation(record.m_componentLocation)
43 {
44 }
45 
48 {
49  if (this != &rhs)
50  {
54  }
55  return *this;
56 }
57 
59  std::ostream& out, const std::string& prefix) const
60 {
61  out << prefix << "ComponentId: "
62  << m_componentId << "\n"
63  << prefix << "ComponentIdString: "
65  << prefix << "ComponentLength: "
66  << m_componentLength << "\n"
67  << prefix << "ComponentLocation: "
68  << m_componentLocation << "\n";
69  return out;
70 }
71 
73 {
74  return data.print(out);
75 }
76 
79 {
80  if(in)
81  {
82  in.read((char*)&m_componentId, 2);
83  in.read((char*)&m_componentLength, 4);
84  in.read((char*)&m_componentLocation, 4);
85 
86  if( ossim::byteOrder() != byteOrder)
87  {
88  // swap to native
89  ossimEndian anEndian;
90  anEndian.swap(m_componentId);
91  anEndian.swap(m_componentLength);
92  anEndian.swap(m_componentLocation);
93  }
94  }
95  else
96  {
98  }
99 
101 }
102 
104 {
106  {
107  ossimEndian endian;
108  endian.swap(m_componentId);
109  endian.swap(m_componentLength);
110  endian.swap(m_componentLocation);
111  }
112 
113  out.write((char*)&m_componentId, 2);
114  out.write((char*)&m_componentLength, 4);
115  out.write((char*)&m_componentLocation, 4);
116 
118  {
119  // Swap back to native byte order.
120  ossimEndian endian;
121  endian.swap(m_componentId);
122  endian.swap(m_componentLength);
123  endian.swap(m_componentLocation);
124  }
125 }
126 
128 {
129  clearFields();
130 }
131 
134 {
136 
137  if(in)
138  {
139  clearFields();
140 
141  in.read((char*)&m_locationSectionLength, 2);
142  in.read((char*)&m_locationTableOffset, 4);
143  in.read((char*)&m_numberOfComponentLocationRecords, 2);
144  in.read((char*)&m_locationRecordLength, 2);
145  in.read((char*)&m_componentAggregateLength, 4);
146 
147  if( ossim::byteOrder() != byteOrder )
148  {
149  ossimEndian anEndian;
150  anEndian.swap(m_locationSectionLength);
151  anEndian.swap(m_locationTableOffset);
153  anEndian.swap(m_locationRecordLength);
155  }
156 
157  if(traceDebug())
158  {
160  ossimNotify(ossimNotifyLevel_DEBUG) << std::endl;
161  }
162 
164  for(ossim_uint32 index = 0;
165  (index < m_componentLocationList.size())&&
166  (result == ossimErrorCodes::OSSIM_OK);
167  ++index)
168  {
169  result = m_componentLocationList[index].parseStream(in, byteOrder);
170  }
171  }
172  else
173  {
175  }
176 
177  return result;
178 }
179 
180 
182 {
184  {
185  // Always write in big endian.
186  ossimEndian endian;
188  endian.swap(m_locationTableOffset);
192  }
193 
194  out.write((char*)&m_locationSectionLength, 2);
195  out.write((char*)&m_locationTableOffset, 4);
196  out.write((char*)&m_numberOfComponentLocationRecords, 2);
197  out.write((char*)&m_locationRecordLength, 2);
198  out.write((char*)&m_componentAggregateLength, 4);
199 
201  {
202  // Swap back to native byte order.
203  ossimEndian endian;
205  endian.swap(m_locationTableOffset);
209  }
210 
211  for(ossim_uint32 i = 0; i < m_componentLocationList.size(); ++i)
212  {
213  m_componentLocationList[i].writeStream(out);
214  }
215 }
216 
218  std::ostream& out, const std::string& prefix) const
219 {
220  out << prefix << "LocationSectionLength: "
221  << m_locationSectionLength << "\n"
222  << prefix << "LocationTableOffset: "
223  << m_locationTableOffset << "\n"
224  << prefix << "NumberOfComponentLocationRecords: "
226  << prefix << "LocationRecordLength: "
227  << m_locationRecordLength << "\n"
228  << prefix << "ComponentAggregateLength: "
229  << m_componentAggregateLength << "\n";
230 
232  {
233  std::vector<ossimRpfComponentLocationRecord>::const_iterator i =
234  m_componentLocationList.begin();
235  while (i != m_componentLocationList.end())
236  {
237  (*i).print(out, prefix);
238  ++i;
239  }
240  }
241  return out;
242 }
243 
245 {
247 
248  return getComponent(componentId, result);
249 }
250 
252  ossimRpfComponentLocationRecord &result)const
253 {
254  std::vector<ossimRpfComponentLocationRecord>::const_iterator component =
255  m_componentLocationList.begin();
256 
257  while(component != m_componentLocationList.end())
258  {
259  if((*component).m_componentId == static_cast<unsigned short>(componentId))
260  {
261  result = *component;
262 
263  return true;
264  }
265  ++component;
266  }
267 
268  return false;
269 }
270 
272 {
273  m_componentLocationList.push_back(record);
274 }
275 
277 {
278  m_locationSectionLength = length;
279 }
280 
282 {
283  m_locationTableOffset = offset;
284 }
285 
287 {
289 }
290 
292 {
293  m_locationRecordLength = length;
294 }
295 
297 {
299 }
300 
302 {
308 
309  m_componentLocationList.clear();
310 }
311 
312 std::vector<ossimRpfComponentLocationRecord>& ossimRpfLocationSection::getLocationRecordList()
313 {
315 }
void addComponentRecord(const ossimRpfComponentLocationRecord &record)
Method to add a component location record.
ossim_int32 ossimErrorCode
ossimRpfComponentId
const ossimRpfComponentLocationRecord & operator=(const ossimRpfComponentLocationRecord &rhs)
assignment operator
static const ossimErrorCode OSSIM_OK
void writeStream(std::ostream &out)
Write method.
virtual ossimString getEntryString(ossim_int32 entry_number) const
ossimRpfComponentLocationRecord()
default constructor
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
static const ossimErrorCode OSSIM_ERROR
unsigned short ossim_uint16
bool getComponent(ossimRpfComponentId componentId, ossimRpfComponentLocationRecord &result) const
void setLocationSectionLength(ossim_uint16 length)
std::vector< ossimRpfComponentLocationRecord > m_componentLocationList
std::vector< ossimRpfComponentLocationRecord > & getLocationRecordList()
Brief Direct access to the list of records.
void setLocationRecordLength(ossim_uint16 length)
virtual ossimErrorCode parseStream(std::istream &in, ossimByteOrder endianOrder)
std::ostream & operator<<(std::ostream &out, const ossimRpfComponentLocationRecord &data)
unsigned int ossim_uint32
void setComponentAggregateLength(ossim_uint32 length)
bool hasComponent(ossimRpfComponentId componentId) const
ossimByteOrder
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
void writeStream(std::ostream &out)
Write method.
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
static ossimRpfComponentIdLut * instance()
ossim_uint16 m_numberOfComponentLocationRecords
void setLocationTableOffset(ossim_uint32 offset)
ossimErrorCode parseStream(std::istream &in, ossimByteOrder endianOrder)
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void clearFields()
Clears records and fields.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
void setNumberOfComponentLocationRecords(ossim_uint16 count)