Click here to Skip to main content
13,353,706 members (50,773 online)
Click here to Skip to main content

Stats

24.5K views
20 bookmarked
Posted 28 Oct 2007

How to build an in-memory state engine at runtime

, 28 Oct 2007
A C++ template for an efficient in-memory state engine.
cp
Debug
TagTree.exe
sources
algorithm
container
general
mpl
tag_tree.pdf
//	Copyright � 2007, solosTec
//  All rights reserved.
//---------------------------------------------------------------------
//	License for redistribution is the GNU General Public License v2.
//	See the included readme.txt for details.
//---------------------------------------------------------------------
//	developed by solosTec
//	http://www.solostec.de
//---------------------------------------------------------------------
//
//	$Author: $
//	$Revision: $
/*	$Log: $
*/
//---------------------------------------------------------------------

//#define _WIN32_WINNT 0x0501
#include <iostream>
#include <string>
#include <container/tag_tree.h>

/**
*	Simulate a data source (file or socket). Note that there is 
*	no <code>back()</code> or <code>previous()</code> method required.
*/
class Source
{
public:
	Source();
	char next();
	size_t position() const;

private:
	char const* content_;
	char *  pos_;
};

/**
*	Scanner for a specific syntax.
*/
class Scanner
{
public:
	typedef enum 
	{
		KEY_UNKNOWN,
		KEY_EOS,
		KEY_KEYWORD, 
		KEY_STRING,
		KEY_AND,
	} KEY;

	typedef turban::container::tag_tree < std::string, KEY >	TagTree_;
	typedef TagTree_::MyPtr_	TagTreePtr_;

public:
	Scanner();
	void run( Source& );

private:
	KEY consume( Source& );

private:
	TagTree_	tagTree_;
};

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

osy
Software Developer (Senior)
Switzerland Switzerland
No Biography provided

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 28 Oct 2007
Article Copyright 2007 by osy
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid