ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Types | Inner Classes | Public Fields | Public Methods | Protected Fields | List of all members
AutoSizes Class Reference

Class Description


This class stores and manages tabulator positions and field sizes. The class supports a simple session handling, by storing each value once for the actual output session and a second time for a future session. The motivation for writing this class came from the requirements of logging library ALox. The goals here are:

If used correctly, this class helps to achieve the following:

This approach very well guarantees stable log output widths across sessions. Only if the execution path of a software changes (or logging verbosity setting is changed), adjustments are performed.

To preserve the information across sessions, this class provides methods to transform it's information from and to string representations which can be stored in configuration files.

As the use case of this class is not restricted to log output, this class is exposed as a general utility class of ALib strings.

Public Types

enum  Types { Tabstop, Field }
 

Inner Classes

class  Entry
 

Public Fields

int ActualIndex
 

Public Methods

int Actual (Types type, int requestedSize, int growthPadding)
 
void Consolidate ()
 
void Export (AString target)
 
void Import (AString source, CurrentData session=CurrentData.Clear)
 
void Import (Substring source, CurrentData session=CurrentData.Clear)
 
int Next (Types type, int requestedSize, int growthPadding)
 
void Reset ()
 
void Start ()
 
override String ToString ()
 

Protected Fields

List< Entrydata = new List<Entry>()
 
int dataSize = 0
 

Member Enumeration Documentation

◆ Types

enum Types
strong

The entry type, tab stop or field width.

Enumerator
Tabstop 

denotes a tab stop entry.

Field 

denotes a field width entry.

Member Function Documentation

◆ Actual()

int Actual ( Types  type,
int  requestedSize,
int  growthPadding 
)
inline

Returns the actual auto value stored, respectively, if the given requested size is higher than what is stored, stores and returns the requested size.

In the latter case, the given extra growth is added to the requested size, but only if the value was set at least once before. In other words, the extra size is added only with the second growth and each subsequent one.

The requested size in addition replaces the current "session" value if it is higher than the currently stored value. To this value, the growth padding is not added.

Parameters
typeThe type of entry.
requestedSizeThe minimum size that is requested.
growthPaddingAdded to the new size, if the requested size is greater than the stored size and if the stored size does not equal -1.
Returns
The (new) size of the auto field.

◆ Consolidate()

void Consolidate ( )
inline

Consolidates the values. This method is usually not invoked directly. Instead, it is invoked with method Import.

The method loops through all values and copies the session values to the actual ones. The difference of both values is summed up during the loop and entries of type Types.Tabstop are adjusted by that difference. As a result, the new values represent the smallest output format that fits all rows, if the same output is performed as in the previous "session".

◆ Export()

void Export ( AString  target)
inline

Exports the current session values by converting the stored values to a string representation and appending them to the given AString object.

The format of the entries written into the string is "(T|F,Actual,Measured) which should be self-explanatory.

Parameters
targetThe AString to receive the our values

◆ Import() [1/2]

void Import ( AString  source,
CurrentData  session = CurrentData.Clear 
)
inline

Imports values from the given AString by parsing it using overloaded method Import.

Parameters
sourceThe AString that is parsed for the numbers
sessionIf CurrentData.Keep the current values are stored to be the last sessions' data and current values are set to 0. If CurrentData.Clear, which is the default, both, current values and session values are taken from the string.

◆ Import() [2/2]

void Import ( Substring  source,
CurrentData  session = CurrentData.Clear 
)
inline

Imports values from the given Substring by parsing it. Usually, string data are used for importing values was previously generated with method Export.

If parameter session equals Clear (which is the default), then after the import, method Consolidate is invoked.

Note
Parsing is 100% error tolerant. If the given string does not contain what is expected (see method Export), then only a part or just nothing is imported. This is due to the purpose of this class, which is to allow nicer, tabbed output. If this is not possible due to import problems, the system should work normally still.
In debug compilations, an ALIB_DBG.WARNING is written.
Parameters
sourceThe String that is parsed for the exported data.
sessionDenotes if Consolidate is to be invoked after import. Defaults to Clear.

◆ Next()

int Next ( Types  type,
int  requestedSize,
int  growthPadding 
)
inline

Invokes Actual and then increases the internal position counter.

Parameters
typeThe type of entry.
requestedSizeThe minimum size that is requested.
growthPaddingAdded to the new size if the requested size is greater than the stored size and if the stored size does not equal -1.
Returns
The (new) size of the auto field.

◆ Reset()

void Reset ( )
inline

Resets the all values, current ones and the once of the currently measured session.

◆ Start()

void Start ( )
inline

Initializes a new query sequence, which is a series of invocations of method Next.

◆ ToString()

override String ToString ( )
inline

This is for debugging purposes. E.g. this enables the Monodevelop IDE to display object descriptions in the debugger.

Returns
A human readable string representation of this object.

Member Data Documentation

◆ ActualIndex

int ActualIndex

The actual index requested by Next. This is reset to 0 with every invocation of Start.

◆ data

List<Entry> data = new List<Entry>()
protected

The current and measured sizes.

◆ dataSize

int dataSize = 0
protected

The number of entries used in data. (The list is never cleared, instead entries are reused after a reset).


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