Click here to Skip to main content
15,895,656 members
Articles / Web Development / HTML

Logician: A Table-based Rules Engine Suite in C++/.NET/JavaScript using XML

Rate me:
Please Sign up or sign in to vote.
4.90/5 (52 votes)
8 Mar 2017GPL314 min read 104.4K   6.8K   173  
Overview of a cross-platform spreadsheet-based rules enigne with algorithms implemented in C++ and JavaScript, and wrappers to C#/.NET/WinRT
/////////////////////////////////////////////////////////////////////////////
// Name:        ProjectManager.h
// Purpose:     Manages project related info for all tables, saving, loading, etc
// Author:      Eric D. Schmidt
// Modified by:
// Created:     07/01/2010
// Copyright:   (c) 2009 - 2015 Eric D. Schmidt, DigiRule Solutions LLC
// Licence:     GNU GPLv2
/*
	DecisionLogic is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    DecisionLogic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DecisionLogic.  If not, see <http://www.gnu.org/licenses/>.
*/
/////////////////////////////////////////////////////////////////////////////
#pragma once

#ifndef PROJECTMANAGER
#define PROJECTMANAGER

#include <string>
#include <set>
#include <map>
#include <vector>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include "StringTable.h"
#include "DataSet.h"


using namespace std;

class ProjectManager
{
public:
	ProjectManager(void);
	~ProjectManager(void);

	void Reset();
	bool SaveProjectFile();
	bool SaveNewProjectFileAs(wstring path);
	bool LoadProjectFile(wstring path);
	bool SaveDataSet(wstring name, wstring path, DataSet<wstring>* ds, bool GetAll);
	DataSet<wstring> LoadDataSet(wstring name);
	bool DeleteDataSet(wstring name);
	bool RenameDataSet(wstring oldName, wstring newName);
	bool RenameDataSetFolder(wstring oldFolder, wstring newFolder);
	bool AddDataSetFile(wstring name, wstring full_path);
	bool MoveFile(wstring name, wstring oldFolder, wstring newFolder);
	wstring GetProjectWorkingPath() {return m_project_working_path;}
	void WriteAllDataSetsToXMLFile(wstring savePath);
	StringTable<wstring>* GetProjectTable() {return m_project_files;}
	void SetDebugStatus(bool status, wstring con, vector<wstring> selectedDebugTables)
		{m_deubgStaus = status; m_DebugConnection = con; m_SelectedTables = selectedDebugTables;}
	void SetCompilerOptions(wstring js, wstring py)
		{m_jsCode = js; m_pyCode = py;}
	vector<wstring> GetProjectTableNames();
	vector<wstring> GetProjectTableNames(wstring path);
	vector<wstring> GetProjectFilePaths();
	wstring GetConnection() {return m_DebugConnection;}
	wstring GetJavascriptCode() {return m_jsCode;}
	wstring GetPythonCode() {return m_pyCode;}
	vector<wstring> GetSelectedDebugTables() {return m_SelectedTables;}
	wstring GetProjectFilePath() {return m_project_full_path_name;}
	wstring GetProjectName() {return m_project_name;}
	wstring GetProjectTitle();
	set<wstring>* GetProjectStrings() {return &stringCollection;}
	xmlDocPtr LoadTableRawXML(wstring name);
	bool TableIsGetAll(wstring name);

	map<wstring, vector<wstring> > GlobalORs;

private:
	xmlDocPtr GetProjectFileXML();
	StringTable<wstring>* ReadProjectFile(wstring path);
	void GetXMLValuesForCell(wstring cellText, long &operation, wstring &saveText, bool bReplaceORs);
	vector<wstring> ParseValueForGets(wstring val);
	void WriteXMLForTable(xmlNodePtr tableDataNode, StringTable<wstring>* table, string tableXMLID, bool bWriteIndexes);
	wstring ReplaceAGet(wstring &newString);
	xmlDocPtr GetDataSetXML(DataSet<wstring>* ds, bool GetAll);
	DataSet<wstring> ReadXML(wstring path);
	StringTable<wstring> CreateDataTableFromNodes(string nodeName, xmlDocPtr doc);
	wstring GetCellValueWithOperation(wstring text, long operation);
	void WriteXML(DataSet<wstring> ds, xmlDocPtr doc);
	void SaveStringDefs(xmlDocPtr doc);
	vector<wstring> CheckForOrs(wstring text);
	wstring GetFilePathForTableName(wstring name);
	void UpdateGlobalORs();

	wstring m_project_name;
	wstring m_project_working_path;
	wstring m_project_full_path_name;
	StringTable<wstring> *m_project_files;
	set<wstring> stringCollection;
	map<wstring, size_t> stringDictionary;

	bool m_deubgStaus;
	wstring m_DebugConnection;
	wstring m_CompiledName;
	vector<wstring> m_SelectedTables;

	wstring m_jsCode;
	wstring m_pyCode;
};

#endif

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 GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
United States United States
I have extensive experience developing software on both Linux and Windows in C++ and Python. I have also done a lot of work in the C#/.NET ecosystem. I currently work in the fields of robotics and machine learning, and also have a strong background in business automation/rules engines.

Comments and Discussions