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 "./FixedDatum.h"
33 using namespace DATA_TYPE
;
34 using namespace ENUMS
;
36 //////////////////////////////////////////////////////////////////////////
38 //////////////////////////////////////////////////////////////////////////
40 FixedDatum::FixedDatum() :
43 memset( m_cDatumValue
, 0, 4 );
46 //////////////////////////////////////////////////////////////////////////
48 FixedDatum::FixedDatum( KDataStream
& stream
)
53 //////////////////////////////////////////////////////////////////////////
55 FixedDatum::~FixedDatum()
59 //////////////////////////////////////////////////////////////////////////
61 void FixedDatum::SetDatumID( DatumID ID
)
66 //////////////////////////////////////////////////////////////////////////
68 DatumID
FixedDatum::GetDatumID() const
70 return ( DatumID
)m_ui32DatumID
;
73 //////////////////////////////////////////////////////////////////////////
75 void FixedDatum::GetDatumValue( KOCTET
* Buffer
, KUINT16 BufferSize
) const
77 if( BufferSize
< 4 )throw KException( __FUNCTION__
, BUFFER_TOO_SMALL
);
78 memcpy( Buffer
, m_cDatumValue
, 4 );
81 //////////////////////////////////////////////////////////////////////////
83 KString
FixedDatum::GetAsString() const
87 NetToKUINT32
NetToSys( m_cDatumValue
, false );
89 // TODO: maybe determine what the data type should be when printing out, this
90 // could be a lot of work.
92 << "\n\tID: " << GetEnumAsStringDatumID( m_ui32DatumID
)
93 << "\n\tValue(UI32): " << NetToSys
.m_Value
99 //////////////////////////////////////////////////////////////////////////
101 void FixedDatum::Decode( KDataStream
& stream
)
103 if( stream
.GetBufferSize() < FixedDatum::FIXED_DATUM_SIZE
)throw KException( __FUNCTION__
, NOT_ENOUGH_DATA_IN_BUFFER
);
105 stream
>> m_ui32DatumID
;
107 for( KUINT16 i
= 0; i
< 4; ++i
)
109 stream
>> m_cDatumValue
[i
];
113 //////////////////////////////////////////////////////////////////////////
115 KDataStream
FixedDatum::Encode() const
119 FixedDatum::Encode( stream
);
124 //////////////////////////////////////////////////////////////////////////
126 void FixedDatum::Encode( KDataStream
& stream
) const
128 stream
<< m_ui32DatumID
;
130 for( KUINT16 i
= 0; i
< 4; ++i
)
132 stream
<< m_cDatumValue
[i
];
136 //////////////////////////////////////////////////////////////////////////
138 KBOOL
FixedDatum::operator == ( const FixedDatum
& Value
) const
140 if( m_ui32DatumID
!= Value
.m_ui32DatumID
) return false;
141 if( memcmp( m_cDatumValue
, Value
.m_cDatumValue
, 4 ) != 0 ) return false;
145 //////////////////////////////////////////////////////////////////////////
147 KBOOL
FixedDatum::operator != ( const FixedDatum
& Value
) const
149 return !( *this == Value
);
152 //////////////////////////////////////////////////////////////////////////