• entries
    707
  • comments
    1173
  • views
    433318

Waiting on my art...

Sign in to follow this  
Programmer16

89 views

I'm waiting on some of my art for the release, so it might be a little longer (my brother is doing it.) The storyline has been dropped for now, as it's not needed.

-Funny Story-
Just now some guys on Halo 2 wanted me to prove that I was actually a programmer lol. Of course, they made a fun of my name, as almost everybody else ('programmar', 'progamer', etc.) Then I showed them this, but I guess it doesn't really prove anything as there doesn't seem to be much, if any, programming content in here. I think it might be time to fix that!

-Programmering Stuffs-
Alright, my new section. I'll cram something in here as often as possible. We'll start with my config system, which resembles CSS majorly. It consists of 3 classes: ConfigElement, ConfigClass, and CofigFile. You simply load a file using ConfigFile, use your ConfigFile to retrieve a class, and then use the retrieved ConfigClass to find elements. If you notice anything horribly wrong with anything, let me know.

Here's an example file:

// settings.cfg
graphics
{
resolution-width = 800;
resolution-height = 600;
windowed = true;
}



I'll note now that the system is case-sensitive and does not support comments. Parsing is to be done by the user (from a string.) Also, I'd like to note that these are really old classes and I'll be redesigning them after a couple games (they work fine for now, no need to mess with them.)

Anyway, here are the classes:

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Dragonfire Games Code Library
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef _DFTCL_CONFIGREADER_H_
#define _DFTCL_CONFIGREADER_H_

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Header files
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include
#include
#include
#include
#include
#include "dftDebugging.h"
#include "dftDataTypes.h"
#include "dftFileSystem.h"


//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
namespace dft
{
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

class ConfigElement
{
friend class ConfigClass;
friend class ConfigFile;
String Name;
public:
String Value;

ConfigElement();
ConfigElement(const String &Name);
ConfigElement(const String &Name, const String &Value);

const String &GetName() const;
const ConfigElement &operator =(const ConfigElement &Element);
};

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

class ConfigClass
{
String Name;
std::map Elements;
public:
ConfigClass();
ConfigClass(const String &Name);

void AddElement(const String &Name, const ConfigElement &Element);
bool GetElement(const String &Name, ConfigElement &Destination);
};

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

class ConfigFile
{
String FileName;
std::map Classes;
public:
ConfigFile();
ConfigFile(const String &FileName);

void Load(const String &FileName);
bool GetClass(const String &Name, ConfigClass &Destination);
};
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#endif




//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Dragonfire Games Code Library
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "dftConfigReader.h"

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start of dftames namespace
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
namespace dft
{
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[PARAMS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

ConfigElement::ConfigElement()
{
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

ConfigElement::ConfigElement(const String &Name) : Name(Name)
{
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

ConfigElement::ConfigElement(const String &Name, const String &Value) : Name(Name)
{
this->Value = Value;
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

const String &ConfigElement::GetName() const
{
return Name;
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

const ConfigElement &ConfigElement::operator =(const ConfigElement &Element)
{
this->Name = Element.Name;
this->Value = Element.Value;
return *this;
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

ConfigClass::ConfigClass()
{
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

ConfigClass::ConfigClass(const String &Name)
{
this->Name = Name;
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

void ConfigClass::AddElement(const String &Name, const ConfigElement &Element)
{
Elements[Name] = Element;
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

bool ConfigClass::GetElement(const String &Name, ConfigElement &Destination)
{
std::map::const_iterator Iterator = Elements.find(Name);
if(Iterator == Elements.end())
return false;

Destination = Iterator->second;
return true;
}


/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

ConfigFile::ConfigFile()
{
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

ConfigFile::ConfigFile(const String &FileName)
{
Load(FileName);
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

void ConfigFile::Load(const String &FileName)
{
this->FileName = GetAbsoluteFileName(FileName);

std::ifstream Stream(this->FileName.c_str());

if(!Stream.is_open())
throw dft::FileNotFoundException(__FILE__, __LINE__, "Could not find the requested config file.", this->FileName);

String FileData;
char Character = 0;

Stream>>Character;
while(!Stream.eof())
{
FileData += Character;
Stream>>Character;
}
Stream.close();

unsigned int Index = 0;
int Start = 0;
while(Index < FileData.size())
{
Start = Index;
while(Index < FileData.size() && FileData[Index] != '{' && FileData[Index] != '}')
++Index;
String ClassName = FileData.substr(Start, Index - Start);
if(ClassName == "" || ClassName == "\n")
throw dft::UnuseableValueException(__FILE__, __LINE__, dft::StringOps::Format("The source config file (%s) has an unuseable(blank) class name.", ClassName.c_str()));

ConfigClass NewClass(ClassName);

++Index; // skip the {

while(Index < FileData.size() && FileData[Index] != '}')
{
ConfigElement TempElement;

while(Index < FileData.size() && FileData[Index] != '=')
{
if(FileData[Index] != ' ' && FileData[Index] != '\t' && FileData[Index] != '\n')
TempElement.Name += FileData[Index];
++Index;
}
++Index; // skip the =

while(Index < FileData.size() && FileData[Index] != ';')
{
bool InQuotes = false;
if(FileData[Index] == '\"')
InQuotes = !InQuotes;
if(FileData[Index] != '\t' && FileData[Index] != '\n')
{
if(InQuotes)
TempElement.Value += FileData[Index];
else if(!InQuotes && FileData[Index] != ' ')
TempElement.Value += FileData[Index];
}
++Index;
}
++Index; // skip the ;

if(TempElement.GetName() != "}" && TempElement.Value != "}")
NewClass.AddElement(TempElement.GetName(), TempElement);
}
Classes[ClassName] = NewClass;

if(Index > FileData.size())
break;

if(FileData[Index] == '}')
++Index;
}
}

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[DESCRIPTION]
[MEMBERS]
[REMARKS]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

bool ConfigFile::GetClass(const String &Name, ConfigClass &Destination)
{
std::map::iterator Iterator = Classes.find(Name);
if(Iterator == Classes.end())
return false;
Destination = Iterator->second;
return true;
}
}



The only thing you should really have to worry about is replacing throw calls.

Back to gaming stuff for me. I'll get my brother to finish the art ASAP.
Sign in to follow this  


2 Comments


Recommended Comments

Guest Anonymous Poster

Posted

Hmmm, you seem to be quite an eager typer!
I am so incredibly lazy that my "config system" came out with <80 lines, including comments, blanks, implementation and value parsing ;-)

Share this comment


Link to comment
Quote:
Original post by Anonymous Poster
Hmmm, you seem to be quite an eager typer!
I am so incredibly lazy that my "config system" came out with <80 lines, including comments, blanks, implementation and value parsing ;-)


lol, indeed, I love typing.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now