ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
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:

Inner Classes

class  Entry
 
class  Section
 
enum  Status
 

Public Static Fields

static String DEFAULT_FILE_EXTENSION = ".ini"
 

Public Fields

boolean autoSave = false
 
String defaultCommentPrefix = "# "
 
AString fileComments = new AString()
 
AString fileName = new AString()
 
boolean formatIncludeDelimInAttrAlignment = false
 
boolean formatSpaceAfterDelim = true
 
boolean formatSpaceBeforeDelim = false
 
Status lastStatus = Status.OK
 
ArrayList< Integer > linesWithReadErrors = new ArrayList<Integer>()
 
- Public Fields inherited from InMemoryPlugin
ArrayList< Sectionsections = new ArrayList<Section>()
 
- Public Fields inherited from ConfigurationPlugin
XTernalizer stringConverter
 

Public Methods

 IniFile ()
 
 IniFile (String filePathAndName)
 
IniFile.Status readFile ()
 
void reset ()
 
boolean store (Variable variable)
 
IniFile.Status writeFile ()
 
- Public Methods inherited from InMemoryPlugin
 InMemoryPlugin ()
 
boolean load (Variable variable, boolean searchOnly)
 
Section searchOrCreateSection (CharSequence name, AString comments)
 
Section searchSection (CharSequence name)
 
- Public Methods inherited from ConfigurationPlugin
boolean load (Variable variable)
 
boolean 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

void construct (String filePathAndName)
 
InMemoryPlugin.Section createSection (CharSequence name)
 
boolean startsWithCommentSymbol (Substring subs)
 
void writeComments (BufferedWriter os, AString comments, Tokenizer tknzr) throws IOException
 
- Protected Methods inherited from ConfigurationPlugin
 ConfigurationPlugin ()
 

Constructor & Destructor Documentation

◆ IniFile() [1/2]

IniFile ( String  filePathAndName)

Constructs an instance of this class and reads the file. If no file name is given, the file name set to the name of the executed class with extension ".ini". The path is then chosen as follows:

  • on Unix like systems: if exists, to the folder ".config" in the users home directory and just to the users home directory otherwise
  • on Windows OS: if exists, to the folder "AppData/Roaming" in the users home directory and just to the users home directory otherwise

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.

◆ IniFile() [2/2]

IniFile ( )

Overloaded constructor providing default value null for parameter filePathName.

Member Function Documentation

◆ construct()

void construct ( String  filePathAndName)
protected

Implementation helper of the constructors.

Parameters
filePathAndNameThe constructor parameter.

◆ createSection()

InMemoryPlugin.Section createSection ( CharSequence  name)
protected

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

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

Reimplemented from InMemoryPlugin.

◆ getAssignmentPos()

static int getAssignmentPos ( AString  value,
String  alignmentSeparator 
)
staticprotected

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 ( )

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()

void reset ( )

Clears all configuration data.

Reimplemented from InMemoryPlugin.

◆ startsWithCommentSymbol()

boolean startsWithCommentSymbol ( Substring  subs)
protected

Helper method used when reading file.

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

◆ store()

boolean store ( Variable  variable)

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 InMemoryPlugin.

◆ writeComments()

void writeComments ( BufferedWriter  os,
AString  comments,
Tokenizer  tknzr 
) throws IOException
protected

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 ( )

Write all configuration data into the file.

Returns
Returns the Status of the operation.

Member Data Documentation

◆ autoSave

boolean 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

◆ DEFAULT_FILE_EXTENSION

String DEFAULT_FILE_EXTENSION = ".ini"
static

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

◆ 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.

◆ 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

boolean formatIncludeDelimInAttrAlignment = false

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

◆ formatSpaceAfterDelim

boolean formatSpaceAfterDelim = true

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

◆ formatSpaceBeforeDelim

boolean formatSpaceBeforeDelim = false

Denotes if a space should be written before a delimiter.

◆ lastStatus

Status lastStatus = Status.OK

The status.

◆ linesWithReadErrors

ArrayList<Integer> linesWithReadErrors = new ArrayList<Integer>()

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: