From: Kay-Uwe Kasemir <[email protected]>
Date: September 26, 2005 10:58:02 EDT
To: Jeff Hill <[email protected]>
Subject: Re: data access structures, strings
On Sep 23, 2005, at 18:43 , Jeff Hill wrote:
its easy enough to write a
convenience library that implements "destination->r =
data_catalog->find("color")->find("red")->toDouble()" on top of
the data
access minimalist interfaces.
Here's my example of what
the "pulling"
data_catalog->find("color")->find("red")->toInt()
data_catalog->find("color")->find("green")->toInt()
data_catalog->find("color")->find("blue")->toInt()
turns into based on the dataAccess callback mechanism:
class PickRGBPieces : public propertyViewer
{
public:
PickRGBPieces()
{ in_color = have_r = have_g = have_b = false; }
bool isValid()
{ return !in_color && have_r && have_g && have_b; }
int getR()
{ return r; }
int getG()
{ return g; }
int getB()
{ return b; }
void reveal ( const propertyId &, const double &v, const
propertyCatalog &x)
{}
void reveal ( const propertyId &id, const int &v, const
propertyCatalog &x)
{
if (in_color)
{
if (id == red_id)
{
r = v;
have_r = true;
}
else if (id == green_id)
{
g = v;
have_g = true;
}
else if (id == blue_id)
{
b = v;
have_b = true;
}
}
}
void reveal ( const propertyId &, const unsigned int &v, const
propertyCatalog &x)
{}
void reveal ( const propertyId &, const long &v, const
propertyCatalog &x)
{}
void reveal ( const propertyId &, const unsigned long &v, const
propertyCatalog &x)
{}
void reveal ( const propertyId &, const epicsTime &, const
propertyCatalog &x)
{}
void reveal ( const propertyId &, const stringSegment &, const
propertyCatalog &x)
{}
void reveal ( const propertyId &, const enumStateSet & )
{}
void reveal ( const propertyId &, const arraySegment &, const
propertyCatalog &x)
{}
void reveal ( const propertyId &id, const propertyCatalog &x)
{
if (id == color_id)
{
in_color = true;
x.traverse(*this);
in_color = false;
}
}
private:
bool in_color, have_r, have_g, have_b;
int r, g, b;
};
PickRGBPieces rgb;
data_catalog.traverse(rgb);
if (rgb.isValid())
{
cout << "Red : " << rgb.getR() << "\n";
cout << "Green : " << rgb.getG() << "\n";
cout << "Blue : " << rgb.getB() << "\n";
}
-Kay