Click here to Skip to main content
15,886,004 members
Articles / Operating Systems / Windows

INI file reader using the spirit library

Rate me:
Please Sign up or sign in to vote.
4.90/5 (31 votes)
3 Jan 2006CPOL5 min read 106K   1.6K   45  
A simple implementation of an INI file reader using the boost::spirit framework
#ifndef _INI_FILE_H_
#define _INI_FILE_H_

struct Entry
{
	string name;
	string value;
};

struct Category
{
	string name;
	vector<Entry> entries;
};

typedef vector<Category> CategoryList;

class CIniFile
{
	CategoryList m_file;
	int m_crt_category;
	int m_crt_entry;
private:
	int b_CategoryIsValid();
	int b_EntryIsValid();

public:
	CIniFile();
	void ClearAll();

	int m_status;
	void LoadFile(string filename);
	void SaveToFile(string filename);

	int GetNumCategories();
	void SetCategory(int cat);
	int SetCategory(string name);
	string GetCategoryName();
	void AddCategoryUnique(string name);
	void AddCategory(string name);

	int GetNumEntries();
	void SetEntry(int entry);
	int SetEntry(string name);
	int SetEntryByValue(string value);

	string GetEntryName();
	string GetEntryValue();
	string GetEntryValueByName(string name);
	void AddEntryUnique(string name, string value);
	void AddEntry(string name, string value);
	void ChangeEntry(string name, string value);
	void SetValue(string value);

	void DeleteEntry(string name);
	void DeleteEntry(int entry);
	void DeleteByValue(string value);


};



#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 Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions