KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
VariableDatum.h
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
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.
13 
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.
24 
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
29 
30 /********************************************************************
31  class: VariableDatum
32  created: 18/09/2008
33  author: Karl Jones
34 
35  purpose: Stores variable data types and their values. Such as strings.
36  Get as string does not know what the data type is so for now assumes
37  each byte is a ASCII char.
38 
39  Note: See FactoryDecoder for a guide to adding support for using your own VariableDatums.
40 
41  size: 64 bits / 8 octets - Min size
42 *********************************************************************/
43 
44 #pragma once
45 
46 #include "./DataTypeBase.h"
47 #include "./FactoryDecoder.h"
48 #include "./../Extras/KRef_Ptr.h"
49 
50 namespace KDIS {
51 namespace DATA_TYPE {
52 
53 /************************************************************************/
54 // Define the type of pointer we are using for VariableDatum Records,
55 // do we want a weak reference or a ref counter?
56 // By default we use a ref pointer, however if you want to use a standard
57 // pointer or one of your own then simply change it below.
58 /************************************************************************/
60 typedef KDIS::UTILS::KRef_Ptr<VariableDatum> VarDtmPtr; // Ref counter
61 //typedef VariableDatum* VarDtmPtr; // Weak ref
62 
63 class KDIS_EXPORT VariableDatum : public DataTypeBase, public FactoryDecoderUser<VariableDatum>
64 {
65 protected:
66 
68 
70 
71  struct DatumEntry
72  {
73  KOCTET Buffer[8];
74 
76  {
77  memset( Buffer, 0x00, 8 );
78  };
79  };
80 
81  // Holds 64 bits, not all bits may belong to the value as padding is also added.
82  std::vector<DatumEntry> m_v8DatumValue;
83 
84 public:
85 
86  static const KUINT16 VARIABLE_DATUM_SIZE = 8; // Min Size
87 
88  VariableDatum();
89 
91 
92  VariableDatum( KDIS::DATA_TYPE::ENUMS::DatumID ID, const KOCTET * data, KUINT32 sizeInBits );
93 
94  VariableDatum( KDataStream & stream ) throw( KException );
95 
96  virtual ~VariableDatum();
97 
98  //************************************
99  // FullName: KDIS::DATA_TYPE::VariableDatum::SetDatumID
100  // KDIS::DATA_TYPE::VariableDatum::GetDatumID
101  //!Description: Set the datum id, indicates what the datum value
102  //! is for and what format it should be in.
103  // Parameter: DatumID ID
104  //************************************
105  virtual void SetDatumID( KDIS::DATA_TYPE::ENUMS::DatumID ID );
106  virtual KDIS::DATA_TYPE::ENUMS::DatumID GetDatumID() const;
107 
108  //************************************
109  // FullName: KDIS::DATA_TYPE::VariableDatum::GetDatumLength
110  //!Description: Returns length of datum VALUE in bits.
111  // Note: Does not include the datum id or length field.
112  //************************************
113  virtual KUINT32 GetDatumLength() const;
114 
115  //************************************
116  // FullName: KDIS::DATA_TYPE::VariableDatum::GetDatumLength
117  //!Description: Returns length of Datum in octets that it will
118  //! occupy when put into a PDU.
119  //************************************
120  virtual KUINT32 GetPDULength() const;
121 
122  //************************************
123  // FullName: KDIS::DATA_TYPE::VariableDatum::GetDatumValueCopyIntoBuffer
124  // KDIS::DATA_TYPE::VariableDatum::GetDatumValueAsKString
125  // KDIS::DATA_TYPE::VariableDatum::GetDatumValueAsKUINT64
126  // KDIS::DATA_TYPE::VariableDatum::GetDatumValueAsKFLOAT64
127  // KDIS::DATA_TYPE::VariableDatum::ClearDatumValue
128  //!Description: Copy datum value into a buffer or
129  //! return as a privative data type.
130  //! primitives are returned as vectors,
131  //! If the datum length is not a multiple of
132  //! 8 then the last octets are ignored.
133  // Parameter: KOCTET * Buffer
134  // Parameter: KUINT16 BufferSize
135  //************************************
136  virtual void GetDatumValueCopyIntoBuffer( KOCTET * Buffer, KUINT16 BufferSize ) const throw( KException );
137  virtual KString GetDatumValueAsKString() const;
138  virtual std::vector<KUINT64> GetDatumValueAsKUINT64() const;
139  virtual std::vector<KFLOAT64> GetDatumValueAsKFLOAT64() const;
140  virtual void SetDatumValue( const KString & s );
141  virtual void ClearDatumValue();
142 
143  //************************************
144  // FullName: KDIS::DATA_TYPE::VariableDatum::SetDatumValue
145  //!Description: Set value from a byte array ... note that length is in bits.
146  //************************************
147  virtual void SetDatumValue( const KOCTET * data, KUINT32 sizeInBits );
148 
149  //************************************
150  // FullName: KDIS::DATA_TYPE::VariableDatum::GetAsString
151  //!Description: Returns a string representation.
152  //************************************
153  virtual KString GetAsString() const;
154 
155  //************************************
156  // FullName: KDIS::DATA_TYPE::VariableDatum::Decode
157  //!Description: Convert From Network Data.
158  // Parameter: KDataStream & stream
159  //************************************
160  virtual void Decode( KDataStream & stream ) throw( KException );
161 
162  //************************************
163  // FullName: KDIS::DATA_TYPE::VariableDatum::Encode
164  //!Description: Convert To Network Data.
165  // Parameter: KDataStream & stream
166  //************************************
167  virtual KDataStream Encode() const;
168  virtual void Encode( KDataStream & stream ) const;
169 
170  KBOOL operator == ( const VariableDatum & Value ) const;
171  KBOOL operator != ( const VariableDatum & Value ) const;
172 };
173 
174 } // END namespace DATA_TYPES
175 } // END namespace KDIS
unsigned int KUINT32
Definition: KDefines.h:103
ID_Enum
Definition: EnumEntityManagement.h:201
unsigned short int KUINT16
Definition: KDefines.h:101
std::vector< DatumEntry > m_v8DatumValue
Definition: VariableDatum.h:82
Definition: KDefines.h:182
DatumEntry()
Definition: VariableDatum.h:75
KDIS::UTILS::KRef_Ptr< VariableDatum > VarDtmPtr
Definition: VariableDatum.h:59
Definition: KDataStream.h:48
KUINT32 m_ui32DatumID
Definition: VariableDatum.h:67
Definition: DataTypeBase.h:49
bool KBOOL
Definition: KDefines.h:119
std::string KString
Definition: KDefines.h:116
KUINT32 m_ui32DatumLength
Definition: VariableDatum.h:69
char KOCTET
Definition: KDefines.h:108
Definition: FactoryDecoder.h:104
Definition: VariableDatum.h:71
#define KDIS_EXPORT
Definition: KDefines.h:82
Definition: VariableDatum.h:63
Definition: KRef_Ptr.h:73