Facemorph.DataBase
Class iniFile

java.lang.Object
  extended by Facemorph.DataBase.iniFile

public class iniFile
extends java.lang.Object

Loads a ini style data file general format # a comment [block name.sub block name:type] variable1 = 56 variable2 = "a string" variable3 = [13,23,12,14] # a vector The resulting data is stored as a tree of node (starting with 'root') Each node represents a block, containing named variables and child blocks Each block has a 'type' associated with it (a string value) and a name. The full name (or absolute name) of the block (as appears above) involves concatinating the names of all the parent blocks with a '.' between them. Data is accessed first by entering the relevent block (by name) then using the get* or set* commands to enter or retrieve data. Once entry or reading is complete the command leaveBlock() is used to retrieve the block being accessed before entry. Normally this is the parent block, but this is not neccessarily the case is enterBlockAbsolute is used.


Nested Class Summary
static class iniFile.IniFileException
           
static class iniFile.Node
           
 
Field Summary
protected  java.util.Stack<iniFile.Node> blockStack
           
protected  iniFile.Node root
           
 
Constructor Summary
iniFile()
          Create an empty iniFile
iniFile(java.io.File f)
          Create a new iniFile be loading from a file
 
Method Summary
protected  iniFile.Node addBlock(java.lang.String line)
           
protected  void addVariable(java.lang.String line, java.io.BufferedReader r, iniFile.Node currentBlock)
           
protected  boolean createBlock(java.lang.String name)
          Create a new block as a child of this block
 boolean createBlock(java.lang.String name, java.lang.String type)
          Create a new block as a child of this block
 boolean enterBlock(java.lang.String name)
          Enter a named block, must be a child (or sub-child) of the current block
 boolean enterBlockAbsolute(java.lang.String name)
          Enter a named block using a name relative to the root node.
 void enterRootBlock()
          Return to the root block (the stack is maintained, i.e.
 void enterRootBlock(boolean reset)
          Return to the root block (if reset is false the stack is maintained, i.e.
 BigMat getBigMat(java.lang.String key)
           
 BigMat getBigMat(java.lang.String key, BigMat fallback)
           
 java.lang.String getBlockName()
           
 java.util.Vector<java.lang.String> getBlocks()
           
 java.util.Vector<java.lang.String> getBlocksByType(java.lang.String type)
          Search child nodes for all blocks of the required type
 java.lang.String getBlockType()
           
 boolean getBoolean(java.lang.String key)
           
 boolean getBoolean(java.lang.String key, boolean fallback)
           
protected  iniFile.Node getCurrentBlock()
           
 double getDouble(java.lang.String key)
           
 double getDouble(java.lang.String key, double fallback)
           
 int getInt(java.lang.String key)
           
 int getInt(java.lang.String key, int fallback)
           
 java.util.Vector<java.lang.String> getList(java.lang.String key)
           
 java.util.Vector<java.lang.String> getList(java.lang.String key, java.util.Vector<java.lang.String> fallback)
           
 java.lang.String getString(java.lang.String key)
           
 java.lang.String getString(java.lang.String key, java.lang.String fallback)
           
 double[] getVector(java.lang.String key)
           
 double[] getVector(java.lang.String key, double[] fallback)
           
 boolean hasBlock(java.lang.String name)
          find a child block with the given name
 boolean hasBlockAbsolute(java.lang.String name)
          find a child block with the given name relative to the root node
 boolean hasType(java.lang.String type)
          find a child block with the given type
 boolean hasTypeAbsolute(java.lang.String type)
          find a child block with the given type relative to the root node
 boolean hasVariable(java.lang.String key)
          Returns true if the current block contains a variable called $key
static boolean isNumber(java.lang.String in)
           
 boolean leaveBlock()
          return to the previous block in the stack (i.e.
 boolean read(java.io.BufferedReader r)
           
 boolean read(java.io.File f)
           
 void set(java.lang.String key, BigMat value)
           
 void set(java.lang.String key, boolean value)
           
 void set(java.lang.String key, double value)
           
 void set(java.lang.String key, double[] value)
           
 void set(java.lang.String key, int value)
           
 void set(java.lang.String key, java.lang.String value)
           
 void set(java.lang.String key, java.util.Vector<java.lang.String> value)
           
 boolean write(java.io.File f)
           
 boolean write(java.io.PrintStream ps)
           
 boolean write(java.lang.StringBuffer str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected iniFile.Node root

blockStack

protected java.util.Stack<iniFile.Node> blockStack
Constructor Detail

iniFile

public iniFile()
Create an empty iniFile


iniFile

public iniFile(java.io.File f)
        throws java.io.FileNotFoundException
Create a new iniFile be loading from a file

Parameters:
f - file to read from
Throws:
java.io.FileNotFoundException
Method Detail

getCurrentBlock

protected iniFile.Node getCurrentBlock()
Returns:
the Node (block) currently in use

enterBlock

public boolean enterBlock(java.lang.String name)
Enter a named block, must be a child (or sub-child) of the current block

Parameters:
name - the name of the block to enter
Returns:
true if the block is found and entered, false otherwise

enterBlockAbsolute

public boolean enterBlockAbsolute(java.lang.String name)
Enter a named block using a name relative to the root node.

Parameters:
name - the name of the block to enter, this is the name as it appears in the iniFile itself
Returns:
true if the block is found and entered, false otherwise

leaveBlock

public boolean leaveBlock()
return to the previous block in the stack (i.e. the block before the last successful enterBlock() or enterBlockAbsolute() command.

Returns:

enterRootBlock

public void enterRootBlock()
Return to the root block (the stack is maintained, i.e. leaveBlock will return the to previous block)


enterRootBlock

public void enterRootBlock(boolean reset)
Return to the root block (if reset is false the stack is maintained, i.e. leaveBlock will return the to previous block)

Parameters:
reset - set to true to clear the stack

createBlock

protected boolean createBlock(java.lang.String name)
Create a new block as a child of this block

Parameters:
name - the name (relative i.e. no '.'s)
Returns:
true if successful

createBlock

public boolean createBlock(java.lang.String name,
                           java.lang.String type)
Create a new block as a child of this block

Parameters:
name - the name (relative i.e. no '.'s)
type - the type of data stored in this block
Returns:
true if successful

getBlockName

public java.lang.String getBlockName()
Returns:
the name of the present block

getBlockType

public java.lang.String getBlockType()
Returns:
the type of the present block

hasBlock

public boolean hasBlock(java.lang.String name)
find a child block with the given name

Parameters:
name - name of the block to search for
Returns:
true is block is found

hasBlockAbsolute

public boolean hasBlockAbsolute(java.lang.String name)
find a child block with the given name relative to the root node

Parameters:
name - absolute (full) name of the block
Returns:
true if found

hasType

public boolean hasType(java.lang.String type)
find a child block with the given type

Parameters:
name - name of the type to search for
Returns:
true is block is found

hasTypeAbsolute

public boolean hasTypeAbsolute(java.lang.String type)
find a child block with the given type relative to the root node

Parameters:
name - absolute (full) name of the type to search for
Returns:
true is block is found

getBlocks

public java.util.Vector<java.lang.String> getBlocks()
Returns:
a list of names (relative) of all immediate child blocks.

getBlocksByType

public java.util.Vector<java.lang.String> getBlocksByType(java.lang.String type)
Search child nodes for all blocks of the required type

Parameters:
type - type to search for
Returns:
list of (absolute) names of blocks of the required type

hasVariable

public boolean hasVariable(java.lang.String key)
Returns true if the current block contains a variable called $key

Parameters:
key - the name of the variable
Returns:
true if the current block contains a variable called $key

getInt

public int getInt(java.lang.String key)

getBoolean

public boolean getBoolean(java.lang.String key)

getDouble

public double getDouble(java.lang.String key)

getString

public java.lang.String getString(java.lang.String key)

getBigMat

public BigMat getBigMat(java.lang.String key)

getVector

public double[] getVector(java.lang.String key)

getList

public java.util.Vector<java.lang.String> getList(java.lang.String key)

getInt

public int getInt(java.lang.String key,
                  int fallback)

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean fallback)

getDouble

public double getDouble(java.lang.String key,
                        double fallback)

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String fallback)

getBigMat

public BigMat getBigMat(java.lang.String key,
                        BigMat fallback)

getVector

public double[] getVector(java.lang.String key,
                          double[] fallback)

getList

public java.util.Vector<java.lang.String> getList(java.lang.String key,
                                                  java.util.Vector<java.lang.String> fallback)

set

public void set(java.lang.String key,
                int value)

set

public void set(java.lang.String key,
                double value)

set

public void set(java.lang.String key,
                boolean value)

set

public void set(java.lang.String key,
                double[] value)

set

public void set(java.lang.String key,
                BigMat value)

set

public void set(java.lang.String key,
                java.util.Vector<java.lang.String> value)

set

public void set(java.lang.String key,
                java.lang.String value)

read

public boolean read(java.io.File f)
             throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

read

public boolean read(java.io.BufferedReader r)

write

public boolean write(java.io.File f)
              throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

write

public boolean write(java.io.PrintStream ps)

write

public boolean write(java.lang.StringBuffer str)

addBlock

protected iniFile.Node addBlock(java.lang.String line)

addVariable

protected void addVariable(java.lang.String line,
                           java.io.BufferedReader r,
                           iniFile.Node currentBlock)

isNumber

public static boolean isNumber(java.lang.String in)