ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Types | Inner Classes | Public Static Fields | Public Fields | Public Methods | Protected Fields | Protected Static Methods | Protected Methods | List of all members
IniFile Class Reference
Inheritance diagram for IniFile:
[legend]
Collaboration diagram for IniFile:
[legend]

Class Description


Specialization of class InMemoryPlugin, which reads and writes a simple configuration file consisting of sections containing key/value pairs.

This class is provided for the case that no other configuration mechanism is available. In general, application specific configuration mechanisms already exist in other libraries used. Those should be adopted by creating a lean interface plug-in for ALib.

Some remarks on the functionality and supported format:

Public Types

enum  Status { OK, ERROR_OPENING_FILE, ERROR_WRITING_FILE }
 

Inner Classes

class  Entry
 
class  Section
 

Public Static Fields

static String DefaultFileExtension = ".ini"
 

Public Fields

bool AutoSave = false
 
String DefaultCommentPrefix = "# "
 
AString FileComments = new AString()
 
AString FileName = new AString()
 
bool FormatIncludeDelimInAttrAlignment = false
 
bool FormatSpaceAfterDelim = true
 
bool FormatSpaceBeforeDelim = false
 
Status LastStatus = Status.OK
 
List< int > LinesWithReadErrors = new List<int>()
 
- Public Fields inherited from InMemoryPlugin
List< SectionSections = new List<Section>()
 
- Public Fields inherited from ConfigurationPlugin
XTernalizer StringConverter
 

Public Methods

 IniFile (String filePathAndName=null)
 
IniFile.Status ReadFile ()
 
override void Reset ()
 
override bool Store (Variable variable)
 
IniFile.Status WriteFile ()
 
- Public Methods inherited from InMemoryPlugin
 InMemoryPlugin ()
 
override bool Load (Variable variable, bool searchOnly=false)
 
Section SearchOrCreateSection (Object name, AString comments)
 
Section SearchSection (Object name)
 
override bool Store (Variable variable)
 
- Public Methods inherited from ConfigurationPlugin
virtual bool Store (Variable variable, Object externalizedValue)
 

Protected Fields

AString commentChars = new AString( "#;/" )
 
- Protected Fields inherited from ConfigurationPlugin
XTernalizer defaultStringConverter = new XTernalizer()
 

Protected Static Methods

static int getAssignmentPos (AString value, String alignmentSeparator)
 

Protected Methods

override InMemoryPlugin.Section createSection (Object name)
 
bool startsWithCommentSymbol (Substring subs)
 
void writeComments (TextWriter os, AString comments, Tokenizer tknzr)
 
- Protected Methods inherited from ConfigurationPlugin
 ConfigurationPlugin ()
 

Member Enumeration Documentation

◆ Status

enum Status
strong

Status codes

Enumerator
OK 

All went well

ERROR_OPENING_FILE 

File not found when reading. This is not necessarily an error.

ERROR_WRITING_FILE 

An error occurred writing the file .

Constructor & Destructor Documentation

◆ IniFile()

IniFile ( String  filePathAndName = null)
inline

Constructs an instance of this class and reads the file. If no file name is given, the file name set to the process name with extension ".ini" while the file path is retrieved using Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData ).

If the given file name filePathAndName starts with '*', no file is read and field AutoSave is set to false.

Parameters
filePathAndNameThe name (and path) of the file to read and write. Provide "*" to suppress reading a file. Defaults to null.

Member Function Documentation

◆ createSection()

override InMemoryPlugin.Section createSection ( Object  name)
inlineprotectedvirtual

Overrides base classes method to create a section of our type.

Parameters
nameThe name of the section.
Returns
An object of type IniFile.Section.

Reimplemented from InMemoryPlugin.

◆ getAssignmentPos()

static int getAssignmentPos ( AString  value,
String  alignmentSeparator 
)
inlinestaticprotected

Helper method for formatting attributes

Parameters
valueThe value to check
alignmentSeparatorThe string defining the separator.
Returns
Returns the position of the first '=' or ':' character

◆ ReadFile()

IniFile.Status ReadFile ( )
inline

Clears all configuration data and reads the file. It might happen that lines are ignored or otherwise marked as faulty. All numbers of such lines get collected in field LinesWithReadErrors.

Returns
Returns the Status of the operation.

◆ Reset()

override void Reset ( )
inlinevirtual

Clears all configuration data.

Reimplemented from InMemoryPlugin.

◆ startsWithCommentSymbol()

bool startsWithCommentSymbol ( Substring  subs)
inlineprotected

Helper method used when reading file.

Parameters
subsA sub-string.
Returns
true if provided substring starts with comment character.

◆ Store()

override bool Store ( Variable  variable)
inlinevirtual

Creates or replaces existing variable in our storage. If AutoSave is set, the file is written

Parameters
variableThe variable to retrieve.
Returns
true if the variable was written, false if not. The latter might only happen if the variable given was illegal, e.g. empty name.

Reimplemented from ConfigurationPlugin.

◆ writeComments()

void writeComments ( TextWriter  os,
AString  comments,
Tokenizer  tknzr 
)
inlineprotected

Writes a list of comments to the file. Comment lines are started with '#'.

Parameters
osThe output stream to write to.
commentsThe comment lines for the section.
tknzrA temporary tokenizer needed internally.

◆ WriteFile()

IniFile.Status WriteFile ( )
inline

Write all configuration data into the file.

Returns
Returns the Status of the operation.

Member Data Documentation

◆ AutoSave

bool AutoSave = false

If this is set to true, any variable change will lead to writing the file immediately by invoking WriteFile. Defaults to false

◆ commentChars

AString commentChars = new AString( "#;/" )
protected

Characters that start a comment

◆ DefaultCommentPrefix

String DefaultCommentPrefix = "# "

The prefix that is used for comment lines of sections or variables that have been added 'in code' (variables that have not been read from the file). Comments that were read from the file preserve their prefix. If comments including one of the valid prefixes are added to a variable or section 'in code', such prefix is preserved.

◆ DefaultFileExtension

String DefaultFileExtension = ".ini"
static

The standard file extension used for ALib configuration files. Defaults to ".ini"

◆ FileComments

AString FileComments = new AString()

The file header which will be written out as a comment lines with "# " prefixes

◆ FileName

AString FileName = new AString()

The file name. This might include a path or not. Should be set properly before the file is read.

◆ FormatIncludeDelimInAttrAlignment

bool FormatIncludeDelimInAttrAlignment = false

Denotes whether the spaces that are inserted when aligning attributes are located before or behind the delimiter.

◆ FormatSpaceAfterDelim

bool FormatSpaceAfterDelim = true

Denotes if a space should be written after a delimiter. (Applies only to single line mode of writing attributes.)

◆ FormatSpaceBeforeDelim

bool FormatSpaceBeforeDelim = false

Denotes if a space should be written before a delimiter.

◆ LastStatus

Status LastStatus = Status.OK

The status.

◆ LinesWithReadErrors

List<int> LinesWithReadErrors = new List<int>()

Is cleared and filled with faulty line numbers when reading the file. (E.g. when a line is no section and no comment but still has no equal sign ('=').


The documentation for this class was generated from the following file: