NuriaProject Framework  0.1
The NuriaProject Framework
Public Types | Public Member Functions | Friends | List of all members
Nuria::MetaField Class Reference

The MetaField class lets you access fields of types. More...

#include <metaobject.hpp>

Public Types

enum  Access { NoAccess = 0x00, ReadOnly = 0x01, WriteOnly = 0x02, ReadWrite = ReadOnly | WriteOnly }
 

Public Member Functions

 MetaField ()
 
Access access () const
 
MetaAnnotation annotation (int idx) const
 
int annotationCount () const
 
int annotationLowerBound (const QByteArray &name) const
 
int annotationUpperBound (const QByteArray &name) const
 
bool isValid () const
 
QByteArray name () const
 
QVariant read (void *instance) const
 
QByteArray typeName () const
 
bool write (void *instance, const QVariant &value)
 

Friends

class MetaObject
 

Detailed Description

The MetaField class lets you access fields of types.

Access
This class allows read and write access. This will work on NURIA_FIELDs and on 'pure' fields, that is, fields which are public but don't have explicit getters or setters associated. In the latter case Tria will auto-generate these functions.
Note
Static variables are ignored.
NURIA_REQUIRE
Fields support NURIA_REQUIRE backed value checks prior setting a value. Both raw fields and user-defined ones are supported. You can access other member variables and methods as well as the new value itself, which is called like the raw field, or like the first argument in a setter.

A new value is only set if the condition is true. If it doesn't, write() fails and nothing happens.

Please see MetaObject for further information on NURIA_REQUIRE.

Types
Used types must be registered to the Qt meta system using Q_DECLARE_METATYPE. Please note that the usual restrictions apply, meaning you should use a typedef when registering a template type with more than one template parameters. Not registering types won't stop Tria nor the project from compiling though, as Tria will do it for you - But this won't apply to your sources as it's only in the generated output.
Raw fields
When Tria stumbles upon a public member variable, it'll auto-generate accessors for it if it's not annotated using NURIA_SKIP (In which case it's ignored completely).
User-defined accessor methods
Nuria allows the use of user-defiend accessor methods (That is, getter and setter) through the use of the NURIA_READ and NURIA_WRITE annotations. A field may only have one or both defined. Both macros take exactly one argument: The field name. The datatype is deduced by the accessor methods itself.
Note
Tria will raise an error if getter and setter expect different types.

The getter must return the field value and may take optional arguments. The setter must take the field value as first argument and may take additional optional arguments. A setter is allowed to return either void or bool. In the latter case, a result value of true indicates success and false indicates failure. This is passed through to the caller through write().

Accessor methods won't be exposed as usual methods. Custom annotations tacked to accessor methods are applied to the field.

Note
As usual, accessor methods must be public.
Redefining accessors for a field will yield a warning.

Member Enumeration Documentation

Access right flags.

Constructor & Destructor Documentation

Nuria::MetaField::MetaField ( )

Creates a invalid instance.

Member Function Documentation

Access Nuria::MetaField::access ( ) const

Returns access flags for this field.

MetaAnnotation Nuria::MetaField::annotation ( int  idx) const

Returns the MetaAnnotation instance for the annotation at idx.

See also
annotationCount
int Nuria::MetaField::annotationCount ( ) const

Returns the number of known annotations.

See also
annotation
int Nuria::MetaField::annotationLowerBound ( const QByteArray &  name) const

Returns the index of the first annotation name. Returns -1 if there's no annotation called like that.

int Nuria::MetaField::annotationUpperBound ( const QByteArray &  name) const

Returns the index of the last annotation name. Returns -1 if there's no annotation called like that.

bool Nuria::MetaField::isValid ( ) const

Returns true if this instance is valid.

QByteArray Nuria::MetaField::name ( ) const

Returns the name of the field.

QVariant Nuria::MetaField::read ( void *  instance) const

Attempts to read the current value from instance.

QByteArray Nuria::MetaField::typeName ( ) const

Returns the type name of the field.

bool Nuria::MetaField::write ( void *  instance,
const QVariant &  value 
)

Attempts to set the current value int instance. On failure false is returned.


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