Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

expander::expandable< StringType > Class Template Reference

The 'expandable' template class, the foundation of it all. More...

#include <expandlib-expandable.h>

Collaboration diagram for expander::expandable< StringType >:

Collaboration graph
List of all members.

Expand Commands

A list of all the commands this expandable will support This list should be updated every time a command is added. The friend declarations are used because all these classes need access to protected members of this class (primarily the expand function). The expand function could probably be public, but it wasn't meant that way, so for now this should do fine.

expcmd_abbr< StringType > cmd_abbr
expcmd_bpad< StringType > cmd_bpad
expcmd_btrunc< StringType > cmd_btrunc
expcmd_fpad< StringType > cmd_fpad
expcmd_ftrunc< StringType > cmd_ftrunc
expcmd_if< StringType > cmd_if
expcmd_knownvars< StringType > cmd_knownvars
expcmd_lower< StringType > cmd_lower
expcmd_ltrim< StringType > cmd_ltrim
expcmd_numvars< StringType > cmd_numvars
expcmd_rtrim< StringType > cmd_rtrim
expcmd_trim< StringType > cmd_trim
expcmd_unknownvars< StringType > cmd_unknownvars
expcmd_upper< StringType > cmd_upper
class expandcmd< StringType >
 This is needed because of the RegisterWith in expandcmd.

class expcmd_abbr< StringType >
class expcmd_bpad< StringType >
class expcmd_btrunc< StringType >
class expcmd_fpad< StringType >
class expcmd_ftrunc< StringType >
class expcmd_if< StringType >
class expcmd_knownvars< StringType >
class expcmd_lower< StringType >
class expcmd_ltrim< StringType >
class expcmd_numvars< StringType >
class expcmd_rtrim< StringType >
class expcmd_trim< StringType >
class expcmd_unknownvars< StringType >
class expcmd_upper< StringType >

Public Types

typedef ::std::vector< StringType > FParamVectorType
 The type used for the parameter vectors (MSVC wouldn't allow me to use template arguments in these typedefs, or I don't know how it should be done).

typedef ::std::map< StringType,
::expander::expandvartype<
StringType > * > 
FVarMapType
 The type used for the map of variables (MSVC wouldn't allow me to use template arguments in these typedefs, or I don't know how it should be done).

typedef ::std::map< StringType,
::expander::expandcmd< StringType > * > 
FCmdMapType
 The type used for the map of commands (MSVC wouldn't allow me to use template arguments in these typedefs, or I don't know how it should be done).


Public Methods

 expandable (const StringType &value=StringType(_T("")), const bool iee=true, const bool ige=false)
 Constructor, initializes expstr to value and the cmdmap with a default set of commands.

bool expandto (StringType &dest, FVarMapType &vars, ExpandResultsType &results)
 Will call expandable::expand, passing the parameters, as well as expandable::expstr (as source string).

void set_expstr (const StringType &value)
 This will set the expandable string.

StringType get_expstr ()
 This will return the expandable string.


Protected Methods

bool expand (StringType &dest, const StringType &src, const FVarMapType &vars, ExpandResultsType &results)
 Will expand this expandable into dest, using vars and putting the results in results.

const StringType::value_type ConvHexToChar (const StringType &h)
 A function to convert from a hexadecimal string to a char (used by expandable::expand).


Protected Attributes

const bool InlineExpandErrors
 Boolean determining what to do with expand errors.

const bool InlineGeneralErrors
 Boolean determining what to do with general errors.

StringType expstr
 The expandable string.

FCmdMapType cmdmap
 The map of commands.


Detailed Description

template<class StringType = ::std::string>
class expander::expandable< StringType >

The 'expandable' template class, the foundation of it all.

This class holds (among other things) the expandable string and is used for calls to expand. It also holds a map of commands that can be used with this expandable string. The template has one parameter, StringType, normally this would be std::string, but it can be anything you want, as long as it is compatible (perhaps std::wstring)

Todo:
Perhaps use a map type that works similar to a rope, with some elements filled in and other elements asked for (if it can't find a var it will ask some function/functor for it).

Definition at line 123 of file expandlib-expandable.h.


Member Typedef Documentation

template<class StringType = ::std::string>
typedef ::std::map<StringType, ::expander::expandcmd<StringType>*> expander::expandable< StringType >::FCmdMapType
 

The type used for the map of commands (MSVC wouldn't allow me to use template arguments in these typedefs, or I don't know how it should be done).

Definition at line 127 of file expandlib-expandable.h.

template<class StringType = ::std::string>
typedef ::std::vector<StringType> expander::expandable< StringType >::FParamVectorType
 

The type used for the parameter vectors (MSVC wouldn't allow me to use template arguments in these typedefs, or I don't know how it should be done).

Definition at line 125 of file expandlib-expandable.h.

template<class StringType = ::std::string>
typedef ::std::map<StringType, ::expander::expandvartype<StringType>*> expander::expandable< StringType >::FVarMapType
 

The type used for the map of variables (MSVC wouldn't allow me to use template arguments in these typedefs, or I don't know how it should be done).

Definition at line 126 of file expandlib-expandable.h.


Constructor & Destructor Documentation

template<class StringType = ::std::string>
expander::expandable< StringType >::expandable const StringType &    value = StringType(_T("")),
const bool    iee = true,
const bool    ige = false
[inline]
 

Constructor, initializes expstr to value and the cmdmap with a default set of commands.

Definition at line 215 of file expandlib-expandable.h.


Member Function Documentation

template<class StringType = ::std::string>
const StringType::value_type expander::expandable< StringType >::ConvHexToChar const StringType &    h [inline, protected]
 

A function to convert from a hexadecimal string to a char (used by expandable::expand).

Definition at line 185 of file expandlib-expandable.h.

Referenced by expander::expandable< StringType >::expand().

template<class StringType>
bool expander::expandable< StringType >::expand StringType &    dest,
const StringType &    src,
const FVarMapType   vars,
ExpandResultsType   results
[protected]
 

Will expand this expandable into dest, using vars and putting the results in results.

This function iterates through the expandable string (src), using a const_iterator, and uses a mode system for keeping track of what to do.

If it's in the searching mode, it will check wether the current char is one of the delimiter chars, if it isn't it will add the current char to the destination string (dest). If it is one of the delimiting chars it will go into the mode corresponding to the char, or rather one of the 'chk' modes, which will first check wether the input is legal and then decide wether to go in this mode or return to the searching mode (and add the delimiter char, as well as the chars that were processed by the chk mode).

The twocharvar mode converts the two hexadecimal digits it has read to a char and adds that to dest. The twocharvar mode doesn't check wether the digits were legal, but the expandable::ConvHexToChar function does.

The other "delimiter" modes (command and realvar)work in essentially the same way, only checking for their own delimiters and filling other strings. When they encounter parameters, delimited by '(' and ')', they will go to the corresponding 'params' mode. The parameters are seperated by comma's, which can be escaped by a backslash. The parameters are first written into the 'param' variable, and than put into the 'params' vector. If the parameters contain commands or variables with parameters those parameters will be "escaped", the variable 'level' is incremented everytime a '(' is found inside a parameter and decreased when a ')' is found, if level>0 just about anything is simply written into 'param'.

The escaping works by having a variable 'quotemode' that is set to 'backslash' whenever a backslash is found (except when level>0). When quotemode==backslash the normal parsing routine isn't performed, the current char is outputted directly to the current string (pointed to by curstring).

Note:
The expand function APPENDS data to the string dest. This means that you can put anything in front of the string that you would like, but it also means that if you re-use the dest string and don't empty the string each time you use, it will get very large.
Warning:
'expandable::expand' (and any functions called by it) are NOT allowed to delete from rvars (and/or free) elements of rvars they did not create themselves
Parameters:
dest The string that expandable::expand appends the result of the expand operation to.
src The "source" string containing the string to be expanded.
vars The map of variables that is used for this string.
results The results class that is used to keep track of how many variables were processed (and found).

Todo:
This could be cleaned-up/re-organized a little more (make the params modes use a switch?).

Make a for() loop possible: #for(nameofvartouse,fromval,toval[,step],stringtouse) Simple example: #for(myvar,0,9,${myvar}) Would output: 0123456789

Introduce the [somethingincludingsomevar] way to do: #if(somevar,something,) ; where it should also be possible to use more than one var (they should be ORed).

Make it possible to do things like #if(somevar || somevar,a,b)

NOTE: I have already found a way to work around the following 'todo', but it would nevertheless be interesting.Somehow let the commands parse their parameters (to enable better quoting for example, how else would you quote a comparison operator in the first parameter of an if statement?), it might be good idea to somehow make this optional (for speed as well as convenience, at the moment 'if' is the only command that would really benifit from it)

Support something like this: #command(param1,(subparam1,subparam2,(subsubparam1)),param3), this would need some sort of tree structure (an STL-like tree container)

Definition at line 321 of file expandlib-expandable.h.

References expander::CommandDelimiter, expander::expandable< StringType >::ConvHexToChar(), expander::expandresults::FoundVars, expander::expandresults::MissedVars, expander::ParamsCloseChar, expander::ParamsOpenChar, expander::ParamsSeperator, expander::RealVarDelimiter, expander::TwoCharVarDelimiter, expander::VarnameCloseChar, and expander::VarnameOpenChar.

Referenced by expander::expandable< StringType >::expandto().

template<class StringType = ::std::string>
bool expander::expandable< StringType >::expandto StringType &    dest,
FVarMapType   vars,
ExpandResultsType   results
[inline]
 

Will call expandable::expand, passing the parameters, as well as expandable::expstr (as source string).

Definition at line 249 of file expandlib-expandable.h.

References expander::expandable< StringType >::expand().

template<class StringType = ::std::string>
StringType expander::expandable< StringType >::get_expstr   [inline]
 

This will return the expandable string.

Definition at line 255 of file expandlib-expandable.h.

template<class StringType = ::std::string>
void expander::expandable< StringType >::set_expstr const StringType &    value [inline]
 

This will set the expandable string.

Definition at line 252 of file expandlib-expandable.h.


Friends And Related Function Documentation

template<class StringType = ::std::string>
friend class expandcmd< StringType > [friend]
 

This is needed because of the RegisterWith in expandcmd.

Definition at line 150 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_abbr< StringType > [friend]
 

Definition at line 151 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_bpad< StringType > [friend]
 

Definition at line 153 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_btrunc< StringType > [friend]
 

Definition at line 155 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_fpad< StringType > [friend]
 

Definition at line 157 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_ftrunc< StringType > [friend]
 

Definition at line 159 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_if< StringType > [friend]
 

Definition at line 161 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_knownvars< StringType > [friend]
 

Definition at line 163 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_lower< StringType > [friend]
 

Definition at line 165 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_ltrim< StringType > [friend]
 

Definition at line 167 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_numvars< StringType > [friend]
 

Definition at line 169 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_rtrim< StringType > [friend]
 

Definition at line 171 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_trim< StringType > [friend]
 

Definition at line 173 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_unknownvars< StringType > [friend]
 

Definition at line 175 of file expandlib-expandable.h.

template<class StringType = ::std::string>
friend class expcmd_upper< StringType > [friend]
 

Definition at line 177 of file expandlib-expandable.h.


Member Data Documentation

template<class StringType = ::std::string>
expcmd_abbr<StringType> expander::expandable< StringType >::cmd_abbr [protected]
 

Definition at line 152 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_bpad<StringType> expander::expandable< StringType >::cmd_bpad [protected]
 

Definition at line 154 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_btrunc<StringType> expander::expandable< StringType >::cmd_btrunc [protected]
 

Definition at line 156 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_fpad<StringType> expander::expandable< StringType >::cmd_fpad [protected]
 

Definition at line 158 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_ftrunc<StringType> expander::expandable< StringType >::cmd_ftrunc [protected]
 

Definition at line 160 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_if<StringType> expander::expandable< StringType >::cmd_if [protected]
 

Definition at line 162 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_knownvars<StringType> expander::expandable< StringType >::cmd_knownvars [protected]
 

Definition at line 164 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_lower<StringType> expander::expandable< StringType >::cmd_lower [protected]
 

Definition at line 166 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_ltrim<StringType> expander::expandable< StringType >::cmd_ltrim [protected]
 

Definition at line 168 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_numvars<StringType> expander::expandable< StringType >::cmd_numvars [protected]
 

Definition at line 170 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_rtrim<StringType> expander::expandable< StringType >::cmd_rtrim [protected]
 

Definition at line 172 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_trim<StringType> expander::expandable< StringType >::cmd_trim [protected]
 

Definition at line 174 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_unknownvars<StringType> expander::expandable< StringType >::cmd_unknownvars [protected]
 

Definition at line 176 of file expandlib-expandable.h.

template<class StringType = ::std::string>
expcmd_upper<StringType> expander::expandable< StringType >::cmd_upper [protected]
 

Definition at line 178 of file expandlib-expandable.h.

template<class StringType = ::std::string>
FCmdMapType expander::expandable< StringType >::cmdmap [protected]
 

The map of commands.

Definition at line 140 of file expandlib-expandable.h.

Referenced by expander::expandcmd< StringType >::Register().

template<class StringType = ::std::string>
StringType expander::expandable< StringType >::expstr [protected]
 

The expandable string.

Definition at line 137 of file expandlib-expandable.h.

template<class StringType = ::std::string>
const bool expander::expandable< StringType >::InlineExpandErrors [protected]
 

Boolean determining what to do with expand errors.

Definition at line 131 of file expandlib-expandable.h.

template<class StringType = ::std::string>
const bool expander::expandable< StringType >::InlineGeneralErrors [protected]
 

Boolean determining what to do with general errors.

Definition at line 134 of file expandlib-expandable.h.


The documentation for this class was generated from the following file:
Generated on Tue Feb 4 17:24:25 2003 for ExpandLib by doxygen1.3-rc2