class Siena::AttributeValue

Siena C++ API documentation.

## class AttributeValue

> value of an attribute in a notification

## Inheritance:

### Public

Constructors
Access functions
Assignment operators

## Documentation

> An `AttributeValue` stores the value of an attribute. Attributes can be of a pre-defined set of types (SienaType). `AttributeValue` provides methods for accessing and assigning values in the form of C++ types. In particular, an `AttributeValue` of type `Siena_integer` can be assigned to and from an `int`, an `AttributeValue` of type `Siena_string` can be assigned to and from a C++ standard `string`, etc.

> Example:

>         AttributeValue x, y;
>         //
>         // now x.type() == y.type() == Siena_null
>         //
>         x = true;
>         y = x;
>         //
>         // now x.type() == y.type() == Siena_bool
>         //
>         int i = 10;
>         if (x.bool_value()) y = i + 10;
>         x = i + 20;
>         cout << x.int_value() + y.int_value() << endl;
>         i = x;
>         y = "ciao";
>         cout << y.string_value() << endl;

`Constructors`

`AttributeValue()`
  null value

`AttributeValue(const AttributeValue &v)`
  copy constructor

`AttributeValue(const string &)`
  construct from a string

`AttributeValue(const char *)`
  construct from a C-style string

`AttributeValue(int)`
  construct from an `int`

`AttributeValue(bool)`
  construct from a `bool`

`AttributeValue(double)`
  construct from a `double`

`Access functions`

`SienaType type() const`
  returns the actual type of this value

`int& int_value()`
  returns a reference to the value as an integer

  Example:

      	AttributeValue x = 20;
      	cout << x.int_value();
      	x.int_value()++;
      	cout << x.int_value();

  Throws:
    BadType exception is generated when `type() != Siena_integer`

`string& string_value()`
  returns a reference to the value as a string

  Example:

      	AttributeValue x = "ciao";
      	cout << x.string_value();
      	x.string_value() += " ciao";
      	cout << x.string_value();

  Throws:
    BadType exception is generated when `type() != Siena_string`

`operator int () const`
  returns a copy of the value as an integer whenever the `AttributeValue` is used in place of an `int`.

  Example:

      	AttributeValue x = 20;
      	int i = x;

  Throws:
    BadType exception is generated when `type() != Siena_int`

`operator string () const`
  returns a copy of the value as a boolean whenever the `AttributeValue` is used in place of an `int`.

  Example:

      	AttributeValue x = "Siena";
      	string s = x;

  Throws:
    BadType exception is generated when `type() != Siena_string`

`Assignment operators`

`AttributeValue& operator = (const AttributeValue &)`
  copy

`AttributeValue& operator = (const string &)`
  from string

`AttributeValue& operator = (const char *)`
  from C-style string

`AttributeValue& operator = (int)`
  from int

`AttributeValue& operator = (bool)`
  from bool

`AttributeValue& operator = (double)`
  from double

Direct child classes:
  AttributeConstraint

See Also:
  Event SienaType

Alphabetic index HTML hierarchy of classes or Java

This document is part of Siena. Please, direct any comment or suggestion to Antonio Carzaniga