1 /*********************************************************************
2 Copyright 2013 Karl Jones
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 #include "./GridDataType2.h"
33 using namespace DATA_TYPE
;
35 using namespace ENUMS
;
37 //////////////////////////////////////////////////////////////////////////
39 //////////////////////////////////////////////////////////////////////////
41 GridDataType2::GridDataType2() :
48 //////////////////////////////////////////////////////////////////////////
50 GridDataType2::GridDataType2( KDataStream
& stream
)
55 //////////////////////////////////////////////////////////////////////////
57 GridDataType2::GridDataType2( KUINT16 SampleType
, KUINT16 DataRepresentation
, KDataStream
& stream
)
59 m_ui16SmpTyp
= SampleType
;
60 m_ui16DtRep
= DataRepresentation
;
62 stream
>> m_ui16NumValues
;
65 for( KUINT16 i
= 0; i
< m_ui16NumValues
; ++i
)
68 m_vf32Values
.push_back( tmp
);
71 stream
>> m_ui16Padding
;
74 //////////////////////////////////////////////////////////////////////////
76 GridDataType2::GridDataType2( KUINT16 SampleType
, const std::vector
<KFLOAT32
> & Values
) :
77 m_ui16NumValues( Values
.size() ),
78 m_vf32Values( Values
),
81 m_ui16SmpTyp
= SampleType
;
85 //////////////////////////////////////////////////////////////////////////
87 GridDataType2::~GridDataType2()
91 //////////////////////////////////////////////////////////////////////////
93 KUINT16
GridDataType2::GetNumberOfValues() const
95 return m_ui16NumValues
;
98 //////////////////////////////////////////////////////////////////////////
100 KUINT16
GridDataType2::GetSize() const
102 return GRID_DATA_TYPE2_SIZE
+ ( m_ui16NumValues
* 4 );
105 //////////////////////////////////////////////////////////////////////////
107 void GridDataType2:: AddValue( KFLOAT32 V
)
110 m_vf32Values
.push_back( V
);
113 //////////////////////////////////////////////////////////////////////////
115 void GridDataType2::SetValues( const std::vector
<KFLOAT32
> & V
)
118 m_ui16NumValues
= m_vf32Values
.size();
121 ////////////////////////////////////////////////////////////////////////
123 const std::vector
<KFLOAT32
> & GridDataType2::GetValues() const
128 //////////////////////////////////////////////////////////////////////////
130 void GridDataType2::ClearValues()
132 m_vf32Values
.clear();
136 //////////////////////////////////////////////////////////////////////////
138 KString
GridDataType2::GetAsString() const
142 ss
<< GridData::GetAsString()
144 << "\n\tNumber Of Values: " << m_ui16NumValues
147 vector
<KFLOAT32
>::const_iterator citr
= m_vf32Values
.begin();
148 vector
<KFLOAT32
>::const_iterator citrEnd
= m_vf32Values
.end();
149 for( ; citr
!= citrEnd
; ++citr
)
158 //////////////////////////////////////////////////////////////////////////
160 void GridDataType2::Decode( KDataStream
& stream
)
162 if( stream
.GetBufferSize() < GRID_DATA_TYPE2_SIZE
)throw KException( __FUNCTION__
, NOT_ENOUGH_DATA_IN_BUFFER
);
164 m_vf32Values
.clear();
166 GridData::Decode( stream
);
168 stream
>> m_ui16NumValues
;
171 for( KUINT16 i
= 0; i
< m_ui16NumValues
; ++i
)
174 m_vf32Values
.push_back( tmp
);
177 stream
>> m_ui16Padding
;
180 //////////////////////////////////////////////////////////////////////////
182 KDataStream
GridDataType2::Encode() const
186 GridDataType2::Encode( stream
);
191 //////////////////////////////////////////////////////////////////////////
193 void GridDataType2::Encode( KDataStream
& stream
) const
195 GridData::Encode( stream
);
197 stream
<< m_ui16NumValues
;
199 vector
<KFLOAT32
>::const_iterator citr
= m_vf32Values
.begin();
200 vector
<KFLOAT32
>::const_iterator citrEnd
= m_vf32Values
.end();
201 for( ; citr
!= citrEnd
; ++citr
)
206 stream
<< m_ui16Padding
;
209 //////////////////////////////////////////////////////////////////////////
211 KBOOL
GridDataType2::operator == ( const GridDataType2
& Value
) const
213 if( GridData::operator != ( Value
) ) return false;
214 if( m_ui16NumValues
!= Value
.m_ui16NumValues
) return false;
215 if( m_vf32Values
!= Value
.m_vf32Values
) return false;
219 //////////////////////////////////////////////////////////////////////////
221 KBOOL
GridDataType2::operator != ( const GridDataType2
& Value
) const
223 return !( *this == Value
);
226 //////////////////////////////////////////////////////////////////////////