Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Network Development Kit 2.0

, 29 Dec 2006 CPOL
Network Development Kit is a set of simple classes for a client-server architecture.
ndk_demo.zip
NDK_demo
ChatClient
res
ChatClient.ico
NDK
ChatServer
res
ChatServer.ico
NDK
ChatClient.exe
ChatServer.exe
ndk_dll_demo.zip
NDK_dll_demo
ChatClient.exe
ChatServer.exe
NDK.dll
ChatClient
res
ChatClient.ico
ChatServer
res
ChatServer.ico
NDK
NDK.def
res
ndk_dll_src.zip
NDK_dll_src
res
NDK.def
mssccprj.scc
vssver.scc
ndk_src.zip
NDK_src
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// NDK 2.0 - Network Development Kit                                          //
//                                                                            //
// Authors: Sebastien Lachance                                                //
//                                                                            //
// E-mail:  netblitz@rocler.qc.ca                                             //
//                                                                            //
// -------------------------------------------------------------------------- //
//                                                                            //
// Permission to use, copy, modify, and distribute this software for any      //
// purpose and without fee is hereby granted. This is no guarantee about the  //
// use of this software. For any comments, bugs or thanks, please email us.   //
//                                                                            //
// -------------------------------------------------------------------------- //
//                                                                            //
// Targeted Platform: Any Windows version                                     //
//                                                                            //
// Last modification: December 2006                                           //
//                                                                            //
// History:                                                                   //
//                                                                            //
// 1- First release of this file.                                             //
// 2- The class is renamed and some optimizations are applied. Hungarian      //
//    notation is used.                                                       //
// 3- Fix a bug concerning the parameter unLength in GetAt and GetNext.       //
//    A reference is now used.                                                //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Includes                                                                   //
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "NDKDataBuffer.h"

////////////////////////////////////////////////////////////////////////////////
// Defines                                                                    //
////////////////////////////////////////////////////////////////////////////////

// Enumeration of all C++ basic types.
enum NDKDataType
{
	NDKDataUChar,
	NDKDataChar,
	NDKDataUShort,
	NDKDataShort,
	NDKDataUInt,
	NDKDataInt,
	NDKDataULong,
	NDKDataLong,
	NDKDataFloat,
	NDKDataDouble,
	NDKDataString,
	NDKDataBuffer
};


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// CNDKMessageData (concrete class)                                           //
//                                                                            //
// -------------------------------------------------------------------------- //
//                                                                            //
// This class contains one data. All C++ basic types is supported, plus a     //
// CString and an arbitrary length buffer of untyped data.                    //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

class CNDKMessageData
{
public:
	////////////////////////////////////////////////////////////////////////////
	// Constructors / Destructor                                              //
	////////////////////////////////////////////////////////////////////////////

	// Constructor.
	CNDKMessageData();

	// Constructor from a UCHAR.
	CNDKMessageData(UCHAR ucData);

	// Constructor from a char.
	CNDKMessageData(char cData);

	// Constructor from a USHORT.
	CNDKMessageData(USHORT usData);

	// Constructor from a short.
	CNDKMessageData(short sData);

	// Constructor from a UINT.
	CNDKMessageData(UINT unData);

	// Constructor from a int.
	CNDKMessageData(int nData);

	// Constructor from a ULONG.
	CNDKMessageData(ULONG ulData);

	// Constructor from a long.
	CNDKMessageData(long lData);

	// Constructor from a float.
	CNDKMessageData(float fData);

	// Constructor from a double.
	CNDKMessageData(double dData);

	// Constructor from a CString.
	CNDKMessageData(const CString& strData);

	// Constructor from a untyped data.
	CNDKMessageData(LPVOID pData, UINT unLength);

	// Copy-Constructor.
	CNDKMessageData(const CNDKMessageData& messageData);

	// Destructor.
	virtual ~CNDKMessageData();

	////////////////////////////////////////////////////////////////////////////
	// Attributes                                                             //
	////////////////////////////////////////////////////////////////////////////

	// Gets the data type.
	NDKDataType GetDataType() const;

	// Gets the data represented by a UCHAR.
	BOOL Get(UCHAR& ucData) const;

	 // Gets the data represented by a char.
	BOOL Get(char& cData) const;

	// Gets the data represented by a USHORT.
	BOOL Get(USHORT& usData) const;

	// Gets the data represented by a short.
	BOOL Get(short& sData) const;

	// Gets the data represented by a UINT.
	BOOL Get(UINT& unData) const;

	// Gets the data represented by a int.
	BOOL Get(int& nData) const;

	// Gets the data represented by a ULONG.
	BOOL Get(ULONG& ulData) const;

	// Gets the data represented by a long.
	BOOL Get(long& lData) const;

	// Gets the data represented by a float.
	BOOL Get(float& fData) const;

	// Gets the data represented by a double.
	BOOL Get(double& dData) const;

	// Gets the data represented by a CString.
	BOOL Get(CString& strData) const;

	// Gets the data represented by a untyped data.
	BOOL Get(LPVOID pData, UINT& unLength) const;

	////////////////////////////////////////////////////////////////////////////
	// Operations                                                             //
	////////////////////////////////////////////////////////////////////////////

	// Serializes this object.
	void Serialize(CArchive& archive);

	////////////////////////////////////////////////////////////////////////////
	// Operators                                                              //
	////////////////////////////////////////////////////////////////////////////

	// Assignment operator.
	const CNDKMessageData& operator=(const CNDKMessageData& messageData);

private:
	union
	{
		UCHAR  uc;
		char   c;
		USHORT us;
		short  s;
		UINT   un;
		int    n;
		ULONG  ul;
		long   l;
		float  f;
		double d;
	} m_union;
	
	NDKDataType	   m_dataType;
	CString	       m_strData;
	CNDKDataBuffer m_dataBuffer;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ArchieCoder
Software Developer (Senior) Mirego
Canada Canada
My name is Sébastien Lachance.
 
I love C# developing Windows Phone and Windows 8 applications.
 
When I’m not in front of a computer, my hobbies include playing bridge, poker and other card games, biking, reading technology news.
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411019.1 | Last Updated 29 Dec 2006
Article Copyright 2000 by ArchieCoder
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid