chore: KDIS datatypes
[KDIS.git] / KDIS / DataTypes / DataTypeBase.h
blob179b402db82c4a2b173ec54dcb01bbd7bf19c93a
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
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
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 /********************************************************************
31 class: DataTypeBase
32 created: 18/09/2008
33 author: Karl Jones
35 purpose: Base class for all data types, all data types must
36 provide a Decode/Encode functionality.
37 *********************************************************************/
39 #pragma once
41 #include "./../KDefines.h"
42 #include "./Enums/KDISEnums.h"
43 #include "./../KDataStream.h"
44 #include "./../Extras/KUtils.h"
46 namespace KDIS {
47 namespace DATA_TYPE {
49 class KDIS_EXPORT DataTypeBase
51 public:
53 DataTypeBase();
55 virtual ~DataTypeBase();
57 //************************************
58 // FullName: KDIS::DATA_TYPE::DataTypeBase::GetAsString
59 // Description: Returns a string representation.
60 //************************************
61 virtual KString GetAsString() const = 0;
63 //************************************
64 // FullName: KDIS::DATA_TYPE::DataTypeBase::Decode
65 // Description: Convert From Network Data.
66 // Parameter: KDataStream & stream
67 //************************************
68 virtual void Decode( KDataStream & stream ) = 0;
70 //************************************
71 // FullName: KDIS::DATA_TYPE::DataTypeBase::Encode
72 // Description: Convert To Network Data.
73 // Parameter: KDataStream & stream
74 //************************************
75 virtual KDataStream Encode() const = 0;
76 virtual void Encode( KDataStream & stream ) const = 0;
78 friend KDataStream & operator >> ( KDataStream & stream, DataTypeBase * DTB )
80 DTB->Decode( stream );
81 return stream;
84 friend KDataStream & operator << ( KDataStream & stream, DataTypeBase * DTB )
86 DTB->Encode( stream );
87 return stream;
90 // For streaming a data type into a KDataStream,
91 #define KDIS_STREAM ( DataTypeBase * ) &
94 } // END namespace DATA_TYPES
95 } // END namespace KDIS