Cast operator for vector pointer

Hi,

I have the following class:

[code]class DataObject
{
protected:
void* data;

          [...]

public:
DataObject();
virtual ~DataObject();

          [...]

operator Int_t();
operator Float_t();
operator Double_t();
operator Int_t*();
operator Float_t*();
operator Double_t*();
operator vector<Int_t>*();
operator vector<Float_t>*();
operator vector<Double_t>*();

};[/code]

The cast operators are similar to this one:

[code]DataObject::operator vector<Double_t>()
{
if(objectType != OTVector || baseType != BTReal || realType != RTDouble)
{
E_MESSAGE("Wrong object type (requested vector
, is " << typeName << “)”);
throw bad_vartype();
}

return ((vector<double>*)data);

}[/code]

Dictionary is being generated by using #pragma link C++ class DataObject+;

When testing this in interpreted ROOT, I find that the cast operator for the vector pointers is not being called at all. I do something like

DataObject d = DataObjectStore["bla"]; vector<double>* v = (vector<double>*)d;

Any ideas?

Cheers,
Johannes.

Hi,

Currently the interpreter does not resolve properly all type of conversion operators. You would need to compile (via ACLiC for example) your scripts to enable the proper behavior.

By the way, what are you trying to achieve?

Cheers,
Philippe

Hi,

the idea is to build a system, that allocates the memory for the TTree branches dynamically and provides access to the underlying branch data by a map<TString, DataObject>. This works fine already and is also really fast, but to access the data, one needs type aware casting of the DataObject. I came up with three ideas:

  1. Templated Get() function
  2. Overloaded stream inserter type& operator<<(type&, DataObject&)
  3. Overloaded cast operators

The third option is the most convenient in my opinion, since you would only need one line to retrieve the objects.

Cheers,
Johannes.