On Tuesday 09 August 2005 14:57, Kay-Uwe Kasemir wrote:
> Do you (and Ben) think that an interface like the DataDescriptor
> with getType(), getBitsize(), .. would work?
> Or is it necessary to get a
> struct { Type type, int bitsize, ... }
> as you suggested earlier?
It may have advantages to use an abstract data type (for the type
descriptor) instead of a concrete one. However, it should be possible
for generic user code to store the type descriptor along with the data.
Your EpicsDataDescriptor is a pure interface. That means generic user
code must always retrieve all the information bit by bit and construct
its own variant of type descriptor, which I think is not very
convenient. I would recommend to use a non-virtual class, here, that
also contains copy-constructor and operator=, so that it can be passed
(and stored) by value.
Another point: I think that calling inappropriate methods of
EpicsDataDescriptor should throw an exception. For instance, calling
getNumDims() on a type descriptor that does not represent an array
throws an exception.
An alternative would be to use the visitor pattern. A C++ interface
could look like this (sketch):
class TypeDescriptor {
...
void traverse(TypeDescriptorVisitor *visitor);
}
class TypeDescriptorVisitor {
virtual void on_Octet();
virtual void on_Bool();
virtual void on_Integer(bool signed, unsigned bitSize);
virtual void on_Floating(unsigned bitSize);
virtual void on_String();
virtual void on_Timestamp();
virtual void on_Enum(unsigned count, EpicsString *names);
virtual void on_Array(unsigned dimCount, unsigned *sizes,
TypeDescriptor &elemType);
virtual void on_Structure(propertyCatalog &catalog);
virtual void on_Any();
}
where the user code has to create an implementation of this interface
and give DataAccess a reference to an object of this class if it wants
type information.
In case you wonder what the on_Any() method is for: Note that the
methods in class TypeDescriptorVisitor are /not/ pure virtual. This is
because for convenient use they should have default definitions (i.e.
implementations in the base class). The default is to call on_Any and
the latter does nothing. Of course, you can override on_Any() to
provide another default.
Example: Testing whether a type is an integer
// user code:
struct IsInteger : public TypeDescriptorVisitor {
bool isInteger;
virtual void on_Any() { isInteger = false; }
virtual void on_Integer(bool, unsigned) { isInteger = true; }
}
Ben
- References:
- Channel Access Client Interface Bob Dalesio
- Re: Channel Access Client Interface Ralph Lange
- Re: Channel Access Client Interface Kay-Uwe Kasemir
- Navigate by Date:
- Prev:
Re: Channel Access Client Interface Ralph Lange
- Next:
RE: Channel Access Client Interface Jeff Hill
- Index:
2002
2003
2004
<2005>
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: Channel Access Client Interface Kay-Uwe Kasemir
- Next:
RE: Channel Access Client Interface Jeff Hill
- Index:
2002
2003
2004
<2005>
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|