From GridLAB-D Wiki
(Redirected from PROPERTY)
Jump to: navigation, search

gld_property - C++ Module API for properties Template:NEW30

Synopsis

class gld_property {

private: // data
	PROPERTY *prop;
	OBJECT *obj;

public: // constructors/casts
	gld_property(OBJECT *o, PROPERTY *p);
	gld_property(OBJECT *o, char *n);
	gld_property(GLOBALVAR *v);
	gld_property(char *n);
	operator PROPERTY*(void);

public: // read accessors
	int from_string(char *string);
	PROPERTYACCESS get_access(void);
	void* get_addr(void);
	gld_class* get_class(void);
	char* get_description(void);
	gld_keyword* get_first_keyword(void);
	PROPERTYFLAGS get_flags(void);
	char *get_name(void);
	size_t get_size(void);
	gld_type get_type(void);
	size_t get_width(void);
	gld_unit* get_unit(void);
	int to_string(char *buffer, int size);

public: // special operations
	template <class T> void getp(T &value);
	template <class T> void getp(T &value, gld_rlock &lock);
	template <class T> void getp(T &value, gld_wlock &lock);
	template <class T> void setp(T &value);
	template <class T> void setp(T &value, gld_wlock &lock);

public: // keyword operations
	gld_keyword* find_keyword(unsigned long value);
	gld_keyword* find_keyword(char *name);

public: // compare operations
	bool compare(char *op, char *a, char *b=NULL, char *p=NULL);

public: // iterators
	PROPERTY* get_next(void);
	bool is_last(void);
};

Description

The gld_property class provides access to the properties of both objects and global variables.

compare

bool [[#compare|compare[[(char *op, char *a, char *b=NULL, char *part=NULL)
This function compares the property using the operator op to the values a (and b if the operator in inside or outside). If the value part is given and the property supports parts (e.g., complex, enduse), then the part indicated is compared.
The values a and b will be parsed using the property type.
Supported operators are ==, <=, >=, !=, <, >, inside, and outside.
Supported parts depend on the type of the property:

find_keyword

gld_keyword* find_keyword(unsigned long value);
gld_keyword* find_keyword(char *name);
This function will find a keyword given a value or given a name.

from_string

int from_string(char *buffer) 
This function is used to read the string to the value associated with this property and object.

get_access

PROPERTYACCESS get_access(void) 
This function is used to determine the PROPERTYACCESS flags associated with this property.

get_addr

void* get_addr(void) 
This function is used to obtain the memory address of the data associated with this property.

get_class

gld_class* get_class(void) 
This function is used to obtain a pointer to the container of the CLASS associated with this property.

get_description

char* get_description(void) 
This function is used to obtain the description of the property, if any. A NULL pointer is returned if no description is associated with the property.

get_first_keyword

gld_keyword* get_keyword(void) 
This function is used to obtain a pointer to container of the first KEYWORD associated with this property, if any. Keywords are only associated with enumeration and set properties.

get_flags

PROPERTYFLAGS get_flags(void) 
This function is used to obtain the PROPERTYFLAGS associated with this property.

get_name

char* get_name(void) 
This function is used to get the name of the property.

get_next

PROPERTY* get_next(void) 
This is used to find the next property associated with this object.

get_size

size_t get_size(void) 
This function is used to determine the size of the property (in units of size of the primitive type).

get_type

gld_type* get_type(void) 
This function is used to obtain a pointer to the container of the PROPERTYTYPE associated with this property.

get_unit

gld_unit* get_unit(void) 
This function is used to obtain a pointer to container of the UNIT associated with this property.

getp

void getp(PROPERTYTYPE &value) 
This template function is used to get the value associated with this property and object.

gld_property

There are four available constructors.

gld_property(OBJECT *obj, PROPERTY *prop) 
This constructor is used to access a property of an object when the core PROPERTY structure is already available.
gld_property(OBJECT *obj, char *name) 
This constructor is used to access a property of an object when only the name of the property is available.
gld_property(GLOBALVAR *var) 
This constructor is used to access a global variable's property information when the GLOBALVAR structure is already available.
gld_property(char *name) 
This constructor is used to access a global variable's property information when only the name of the variable is available.

is_last

bool is_last(void) 
This is used to determine whether this property is the last in list of properties associated with this object.

PROPERTY

(PROPERTY
This cast is used to gain access to the core PROPERTY structure used by the property.

to_string

int to_string(char *buffer, int size) 
This function is used to write the value associated with this property and object to a string.

setp

void setp(PROPERTYTYPE &value) 
This template is used to set the value associated with this property and object.

Examples

To obtain access a property in another object:

gld_property myvar(my_obj,"varname");

To get the value of the property (assuming it's a double):

double value;
myvar.getp(value);

To set the value of the property (assuming it's a double):

myvar.setp(12.4);

To write the property to a string:

char buffer[256];
myvar.to_string(buffer,sizeof(buffer));

To read the value from a string:

myvar.from_string("18.2");

To compare the value to another value:

if ( myvar.compare("<","0") )
  output_warning("myvar is negative");

Version

The C++ Module API was introduced in Hassayampa (Version 3.0) to support multithreaded modules.

See also