Properties

We are now ready to expand our point class to include access to x,y and z.

    class point : public object {
    public:
	//construction
	point(double x,double y,double z);

	//access
	double get_x() const;
	double get_y() const;
	double get_z() const;

	void set_x(double x);
	void set_y(double y);
	void set_z(double z);
    private:
	double x_,y_,z_;
    };

Above, we have implemented both read and write access to x,y and z.
We'll examine read and write access in turn:

Read access

There are three ways to expose read-access to dynamic data in a class:

in addition, there are three ways to expose read-access to global data in a class:

Here are some examples of the different forms for access:

    //dynamic data access:
    double point::get_x();                   //member-functions
    double point::y_;                        //member-data
    double point_get_z(const point& p);      //free functions as member
    //static data access:
    double get_earth_gravity();              //free function
    3.14                                     //constant value
    static int global_var;                   //Global value

And this is how to expose the above to CliPP:

    //dynamic data access:
    cls.read("x",get_x);                     //member-functions
    cls.read("y",&y_);                       //member-data
    cls.read("z",point_get_z);               //free functions as member
    //static data access:
    cls.read("gravity",get_earth_gravity);   //free function
    cls.read("PI",3.14);                     //constant value
    cls.read("ref",boost::ref(global_var));  //reference to value

static data read access can also be made available globally:

    context* c=parser.get_context();
    //static data access:
    read(c,"gravity",get_earth_gravity);     //free function
    read(c,"PI",3.141);                      //constant value
    read(c,"ref",boost::ref(global_var));    //reference to value

Write access

There are three ways to expose write-access to dynamic data in a class:

in addition, there is two way to expose write-access to global data in a class:

    //dynamic data access:
    void point::set_x(double x);                   //member-functions
    double point::y_;                              //member-data
    void point_set_z(const point& p,double z);     //free functions as member
    //static data access:
    void set_earth_gravity(double g);              //free function
    static int global_var;                         //Global value

And this is how to expose the above to CliPP:

    //dynamic data access:
    cls.write("x",set_x);                    //member-functions
    cls.write("y",&y_);                      //member-data
    cls.write("z",point_set_z);              //free functions as member
    //static data access:
    cls.write("gravity",set_earth_gravity);  //free function
    cls.write("ref",boost::ref(global_var)); //reference to value

static data write access can also be made available globally:

    context* c=parser.get_context();
    //static data access:
    write(c,"gravity",set_earth_gravity);    //free function
    write("ref",boost::ref(global_var));     //reference to value

Read/Write access

If you want to create both read and write access, you can use the read_write function with the same restrictions as above:

    cls.read_write("x",get_x,set_x);
    cls.read_write("y",&y_,set_y);
    cls.read_write("y",&z_,&z);