Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::VariableObserver Class Referenceabstract

Observes Environment variables. More...

#include <geogram/basic/environment.h>

Public Member Functions

 VariableObserver (const std::string &var_name)
 Creates a new variable observer. More...
 
virtual void value_changed (const std::string &new_value)=0
 Receives a change notification. More...
 
virtual ~VariableObserver ()
 Deletes the observer. More...
 
const std::string & observed_variable () const
 Gets the observed variable. More...
 

Detailed Description

Observes Environment variables.

VariableObserver offers the possibility to receive notifications when a variable is changed in an Environment.

To listen to a variable:

  1. Create a class derived class from VariableObserver and implement function value_changed().
  2. Create a MyObserver instance with name "my_variable", it will be automatically attached to the variable in the root Environment.
struct MyObserver : VariableObserver {
MyObserver(const std::string& name) : VariableObserver(name) {}
virtual void value_changed(const std::string& new_value) {
};
std::auto_ptr<MyObserver> myobserver =
new MyObserver("my_variable");
VariableObserver(const std::string &var_name)
Creates a new variable observer.
virtual void value_changed(const std::string &new_value)=0
Receives a change notification.

Definition at line 83 of file environment.h.

Constructor & Destructor Documentation

◆ VariableObserver()

GEO::VariableObserver::VariableObserver ( const std::string &  var_name)

Creates a new variable observer.

This creates a new observer for variable var_name and automatically adds itself to the variable's observers in the root environment.

Parameters
[in]var_namename of the variable observed.

◆ ~VariableObserver()

virtual GEO::VariableObserver::~VariableObserver ( )
virtual

Deletes the observer.

This automatically removes this observer from the root environment.

Member Function Documentation

◆ observed_variable()

const std::string& GEO::VariableObserver::observed_variable ( ) const
inline

Gets the observed variable.

Returns
The name of the variable observed by this observer.

Definition at line 113 of file environment.h.

◆ value_changed()

virtual void GEO::VariableObserver::value_changed ( const std::string &  new_value)
pure virtual

Receives a change notification.

This function is called by the Environment when the variable observed by this observer is modified.

Parameters
[in]new_valuethe new value of the observed variable.

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