My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
TemplateVariant Class Reference

Variant type which can hold one value of a fixed set of types. More...

#include <template.h>

Classes

class  Delegate
 Helper class to create a delegate that can store a function/method call. More...
 

Public Types

enum  Type {
  None, Bool, Integer, String,
  Struct, List, Function
}
 

Public Member Functions

Type type () const
 
QCString typeAsString () const
 
bool isValid () const
 
 TemplateVariant ()
 
 TemplateVariant (bool b)
 
 TemplateVariant (int v)
 
 TemplateVariant (const char *s, bool raw=FALSE)
 
 TemplateVariant (const QCString &s, bool raw=FALSE)
 
 TemplateVariant (TemplateStructIntf *s)
 
 TemplateVariant (TemplateListIntf *l)
 
 TemplateVariant (const Delegate &delegate)
 
 ~TemplateVariant ()
 
 TemplateVariant (const TemplateVariant &v)
 
TemplateVariantoperator= (const TemplateVariant &v)
 
bool operator== (TemplateVariant &other)
 
QCString toString () const
 
bool toBool () const
 
int toInt () const
 
TemplateListIntftoList () const
 
TemplateStructIntftoStruct () const
 
TemplateVariant call (const QValueList< TemplateVariant > &args)
 
void setRaw (bool b)
 
bool raw () const
 

Private Attributes

Type m_type
 
QCString m_strVal
 
union {
   int   m_intVal
 
   bool   m_boolVal
 
   TemplateStructIntf *   m_strukt
 
   TemplateListIntf *   m_list
 
}; 
 
Delegate m_delegate
 
bool m_raw
 

Detailed Description

Variant type which can hold one value of a fixed set of types.

Definition at line 90 of file template.h.

Member Enumeration Documentation

Types of data that can be stored in a TemplateVariant

Enumerator
None 
Bool 
Integer 
String 
Struct 
List 
Function 

Definition at line 139 of file template.h.

Constructor & Destructor Documentation

TemplateVariant::TemplateVariant ( )
inline

Constructs an invalid variant.

Definition at line 164 of file template.h.

Referenced by call().

: m_type(None), m_strukt(0), m_raw(FALSE) {}
TemplateVariant::TemplateVariant ( bool  b)
inlineexplicit

Constructs a new variant with a boolean value b.

Definition at line 167 of file template.h.

: m_type(Bool), m_boolVal(b), m_raw(FALSE) {}
TemplateVariant::TemplateVariant ( int  v)
inline

Constructs a new variant with a integer value v.

Definition at line 170 of file template.h.

: m_type(Integer), m_intVal(v), m_raw(FALSE) {}
TemplateVariant::TemplateVariant ( const char *  s,
bool  raw = FALSE 
)
inline

Constructs a new variant with a string value s.

Definition at line 173 of file template.h.

TemplateVariant::TemplateVariant ( const QCString &  s,
bool  raw = FALSE 
)
inline

Constructs a new variant with a string value s.

Definition at line 176 of file template.h.

TemplateVariant::TemplateVariant ( TemplateStructIntf s)

Constructs a new variant with a struct value s.

Note
. The variant will hold a reference to the object.

Definition at line 147 of file template.cpp.

References TemplateStructIntf::addRef(), and m_strukt.

: m_type(Struct), m_strukt(s), m_raw(FALSE)
{
}
TemplateVariant::TemplateVariant ( TemplateListIntf l)

Constructs a new variant with a list value l.

Note
. The variant will hold a reference to the object.

Definition at line 153 of file template.cpp.

References TemplateListIntf::addRef(), and m_list.

: m_type(List), m_list(l), m_raw(FALSE)
{
}
TemplateVariant::TemplateVariant ( const Delegate delegate)
inline

Constructs a new variant which represents a method call

Parameters
[in]delegateDelegate object to invoke when calling call() on this variant.
Note
Use TemplateVariant::Delegate::fromMethod() and TemplateVariant::Delegate::fromFunction() to create Delegate objects.

Definition at line 195 of file template.h.

: m_type(Function), m_strukt(0), m_delegate(delegate), m_raw(FALSE) {}
TemplateVariant::~TemplateVariant ( )

Destroys the Variant object

Definition at line 159 of file template.cpp.

References List, m_list, m_strukt, m_type, TemplateListIntf::release(), TemplateStructIntf::release(), and Struct.

{
else if (m_type==List) m_list->release();
}
TemplateVariant::TemplateVariant ( const TemplateVariant v)

Constructs a copy of the variant, v, passed as the argument to this constructor.

Definition at line 165 of file template.cpp.

References TemplateListIntf::addRef(), TemplateStructIntf::addRef(), Bool, Function, Integer, List, m_boolVal, m_delegate, m_intVal, m_list, m_raw, m_strukt, m_strVal, m_type, None, String, and Struct.

: m_type(v.m_type), m_strukt(0), m_raw(FALSE)
{
m_raw = v.m_raw;
switch (m_type)
{
case None: break;
case Bool: m_boolVal = v.m_boolVal; break;
case Integer: m_intVal = v.m_intVal; break;
case String: m_strVal = v.m_strVal; break;
case Struct: m_strukt = v.m_strukt; m_strukt->addRef(); break;
case List: m_list = v.m_list; m_list->addRef(); break;
case Function: m_delegate= v.m_delegate;break;
}
}

Member Function Documentation

TemplateVariant TemplateVariant::call ( const QValueList< TemplateVariant > &  args)
inline

Return the result of apply this function with args. Returns an empty string if the variant type is not a function.

Definition at line 272 of file template.h.

References Function, m_delegate, m_type, and TemplateVariant().

Referenced by TemplateNodeVariable::render(), TemplateNodeFor::render(), TemplateNodeCycle::render(), and ExprAstFunctionVariable::resolve().

{
if (m_type==Function) return m_delegate(args);
return TemplateVariant();
}
bool TemplateVariant::isValid ( ) const
inline
TemplateVariant & TemplateVariant::operator= ( const TemplateVariant v)

Assigns the value of the variant v to this variant.

Definition at line 181 of file template.cpp.

References TemplateListIntf::addRef(), TemplateStructIntf::addRef(), Bool, Function, Integer, List, m_boolVal, m_delegate, m_intVal, m_list, m_raw, m_strukt, m_strVal, m_type, None, TemplateListIntf::release(), TemplateStructIntf::release(), String, and Struct.

{
// assignment can change the type of the variable, so we have to be
// careful with reference counted content.
TemplateListIntf *tmpList = m_type==List ? m_list : 0;
Type tmpType = m_type;
m_raw = v.m_raw;
switch (m_type)
{
case None: break;
case Bool: m_boolVal = v.m_boolVal; break;
case Integer: m_intVal = v.m_intVal; break;
case String: m_strVal = v.m_strVal; break;
case Struct: m_strukt = v.m_strukt; m_strukt->addRef(); break;
case List: m_list = v.m_list; m_list->addRef(); break;
case Function: m_delegate= v.m_delegate;break;
}
// release overwritten reference counted values
if (tmpType==Struct && tmpStruct) tmpStruct->release();
else if (tmpType==List && tmpList ) tmpList->release();
return *this;
}
bool TemplateVariant::operator== ( TemplateVariant other)
inline

Compares this QVariant with v and returns true if they are equal; otherwise returns false.

Definition at line 211 of file template.h.

References List, m_list, m_strukt, m_type, None, Struct, and toString().

{
if (m_type==None)
{
return FALSE;
}
{
return m_list==other.m_list; // TODO: improve me
}
{
return m_strukt==other.m_strukt; // TODO: improve me
}
else
{
return toString()==other.toString();
}
}
bool TemplateVariant::raw ( ) const
inline

Returns whether or not the value of the Value is raw.

See Also
setRaw()

Definition at line 287 of file template.h.

References m_raw.

Referenced by TemplateNodeVariable::render(), and TemplateNodeCycle::render().

{ return m_raw; }
void TemplateVariant::setRaw ( bool  b)
inline

Sets whether or not the value of the Variant should be escaped or written as-is (raw).

Parameters
[in]bTRUE means write as-is, FALSE means apply escaping.

Definition at line 282 of file template.h.

References m_raw.

Referenced by TemplateNodeTree::renderChildren().

{ m_raw = b; }
bool TemplateVariant::toBool ( ) const

Returns the variant as a boolean.

Definition at line 208 of file template.cpp.

References Bool, TemplateListIntf::count(), Function, Integer, List, m_boolVal, m_intVal, m_list, m_strVal, m_type, None, String, and Struct.

Referenced by TemplateNodeIf::render(), ExprAstNegate::resolve(), and ExprAstBinary::resolve().

{
switch (m_type)
{
case None: return FALSE;
case Bool: return m_boolVal;
case Integer: return m_intVal!=0;
case String: return !m_strVal.isEmpty();
case Struct: return TRUE;
case List: return m_list->count()!=0;
case Function: return FALSE;
}
return FALSE;
}
int TemplateVariant::toInt ( ) const
TemplateListIntf* TemplateVariant::toList ( ) const
inline
QCString TemplateVariant::toString ( ) const
inline
TemplateStructIntf* TemplateVariant::toStruct ( ) const
inline

Returns the pointer to struct referenced by this variant or 0 if this variant does not have struct type.

Definition at line 264 of file template.h.

References m_strukt, m_type, and Struct.

Referenced by FilterGet::apply(), FilterListSort::apply(), FilterGroupBy::apply(), FilterAlphaIndex::apply(), computeMaxDepth(), computeNumNodesAtLevel(), computePreferredDepth(), FilterFlatten::flatten(), TemplateContextImpl::get(), getPathListFunc(), TemplateNodeFor::render(), and TemplateNodeTree::renderChildren().

{
return m_type==Struct ? m_strukt : 0;
}
Type TemplateVariant::type ( ) const
inline
QCString TemplateVariant::typeAsString ( ) const
inline

Return a string representation of the type of the value stored in the variant

Definition at line 145 of file template.h.

References Bool, Function, Integer, List, m_type, None, String, and Struct.

Referenced by TemplateNodeFor::render(), and TemplateNodeTree::renderChildren().

{
switch (m_type)
{
case None: return "none";
case Bool: return "bool";
case Integer: return "integer";
case String: return "string";
case Struct: return "struct";
case List: return "list";
case Function: return "function";
}
return "invalid";
}

Member Data Documentation

union { ... }
bool TemplateVariant::m_boolVal

Definition at line 295 of file template.h.

Referenced by operator=(), TemplateVariant(), toBool(), toInt(), and toString().

Delegate TemplateVariant::m_delegate
private

Definition at line 299 of file template.h.

Referenced by call(), operator=(), and TemplateVariant().

int TemplateVariant::m_intVal

Definition at line 294 of file template.h.

Referenced by operator=(), TemplateVariant(), toBool(), toInt(), and toString().

TemplateListIntf* TemplateVariant::m_list

Definition at line 297 of file template.h.

Referenced by operator=(), operator==(), TemplateVariant(), toBool(), toInt(), toList(), and ~TemplateVariant().

bool TemplateVariant::m_raw
private

Definition at line 300 of file template.h.

Referenced by operator=(), raw(), setRaw(), and TemplateVariant().

TemplateStructIntf* TemplateVariant::m_strukt

Definition at line 296 of file template.h.

Referenced by operator=(), operator==(), TemplateVariant(), toStruct(), and ~TemplateVariant().

QCString TemplateVariant::m_strVal
private

Definition at line 291 of file template.h.

Referenced by operator=(), TemplateVariant(), toBool(), toInt(), and toString().

Type TemplateVariant::m_type
private

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