#include<iostream>
#include<string>
#include<vector>
#include<rapidjson/document.h>
#include<rapidjson/filereadstream.h>
#include<fstream> 

using namespace std;
using namespace rapidjson;


class FSMBase
{
public:
	string StateName;
	string EventName;
	std::vector<FSMBase*> subitem;

public:

	FSMBase()
	{
		std::cout << "default constructor called" << std::endl;
	}

	void getdata()
	{
		std::cout << "FSMBase called" << std::endl;
	}

	virtual void Add(FSMBase* b1)
	{
		subitem.push_back(b1);
		b1->getdata();
	}

	~FSMBase()
	{
		std::cout << " destructor called" << std::endl;
	}
};


class premitivetool :public FSMBase
{
public:

	void Add(FSMBase* b1)
	{
		subitem.push_back(b1);
		b1->getdata();
	}
};

class Event : public FSMBase
{
	string ActionType;
	string ActionParam;
public:

	void getdata(string Name, string ActType, string ActPar)
	{
		EventName = Name;
		ActionType = ActType;
		ActionParam = ActPar;
		std::cout << " " << EventName << " " << ActionType << " " << ActionParam << std::endl;
	}
};

class state :public FSMBase
{
	string EntreyMethodName;
	std::vector<Event*> eventitem;
public:

	void getdata(string Name, string Methodname)
	{
		StateName = Name;
		EntreyMethodName = Methodname;
		std::cout << "  " << StateName << "  " << EntreyMethodName << std::endl;
	}

	void Add(FSMBase* fsmbase1)
	{
		subitem.push_back(fsmbase1);
		fsmbase1->getdata();
	}
};

int main()
{
	state* State1;
	Event* Event1;
	State1 = new state;	
	Event1 = new Event;
	State1->getdata("StartToolState", "EnterStartTool");
	State1->Add(Event1);

	premitivetool* prtool1;
	prtool1 = new premitivetool;
	prtool1->Add(State1);

	state* State2;
	Event* Event2;
	State2 = new state;
	Event2 = new Event;
	Event2->getdata("MotionEvent", "InvokeMethod", "MoveToolPoints");

	State1->Add(Event2);
	prtool1->Add(State2);

	delete Event2;
	delete State2;
	delete State1;
	delete Event1;
	delete prtool1;

	// Open the file 
	ifstream file("FSMImplementationJSON.json");
	if (!file.is_open()) {
		cerr << "Could not open file: FSMImplementationJSON.json" << endl;
		return 1;
	}

	// Read the entire file into a string 
	string json((istreambuf_iterator<char>(file)),
		istreambuf_iterator<char>());

	Document doc;

	// Parse the JSON data 
	doc.Parse(json.c_str());
	//std::cout << doc["Name"].GetString() << std::endl;

	// Check for parse errors 
	if (doc.HasParseError()) {
		cerr << "Error parsing JSON: "
			<< doc.GetParseError() << endl;
		return 1;
	}
	FILE* fp;
	fopen_s(&fp, "FSMImplementationJSON.json", "rb");

	if (fp == nullptr) {
		cerr << "Error opening the file" << std::endl;
		return 1;
	}

	char readBuffer[65536];
	rapidjson::FileReadStream is(fp, readBuffer, sizeof(readBuffer));
	rapidjson::Document d;
	d.ParseStream(is);


	if (d.HasMember("State") && d["State"].IsArray())
	{
		const rapidjson::Value& State = d["State"];
		std::cout << "State: ";
		for (rapidjson::SizeType i = 0; i < State.Size(); i++)
		{
			/*if (d.HasMember("Name") && d["Name"].IsString())
			{
				std::string name = d["Name"].GetString();
				std::cout << "name" << name << std::endl;
			}
			if (d.HasMember("EntryMethodName") && d["EntryMethodName"].IsString())
			{
				std::string entryname = d["EntryMethodName"].GetString();
				std::cout << "entryname" << entryname << std::endl;
			}*/
			if (State[i].IsString()) {
				std::string state = State[i].GetString();
				std::cout << state << " ";
			}
		}
		std::cout << std::endl;
	}
	//// Close the file 
	if (fp)
		fclose(fp);
	return 0;
}
Is the json file reading takes place in this code or not?