B
bartek
Hello,
I've been pondering with this for quite some time now, and finally
decided to ask here for suggestions. I'm kind of confused, actually...
Maybe I'm thinking too much...
Brain dump follows...
I need a class to represent a variable, with an associated data type
and/or value. Though, I don't want it to be a variant type, and not a
'convenience' class either.
The variable objects will be used in variable lists (a'la symbol tables),
so they are going to be polymorphic.
Now to the point...
The variable type is determined by the following factors:
1. raw data type (int, float, string, etc...)
2. array width (if it's an array of p.1)
3. storage class modifier
My dilemma concerns the actual design of the way how to access those
variables in different parts of the system.
The lists of variables are used in quite different situations.
For example, in generating function prototypes (type declarations),
carrying actual data around the system, translating data coming from
external sources.
The above requirements are pushing me towards a consequent use of the
visitor pattern. Though, I'm completely puzzled on how to apply visitor
to a type which is determined by 3 factors (as shown above).
It all seems as a total maintenance disaster at the moment...
THE Question:
Is there a simple way (or a way to simplify) such a case of three-way-
visitation?
Should I go for explicit definition of each type?
E.g.
Given types Int and Float, and storage classes Uniform and Varying,
define every possible combination of data type, array specifier, and
storage class modifier. ouch!
class Variable ... // the root
class UniformInt : public Variable ...
class UniformIntArray : public Variable ...
class VaryingInt : public Variable ...
class VaryingIntArray : public Variable ...
class UniformFloat : public Variable ...
etc...
Maybe I could nest it in some way?
E.g.
class StorageSpec ... // root
class Uniform : public StorageSpec ...
class Varying : public StorageSpec ...
class Variable ... // root
class Float : public Variable {
StorageSpec* m_storage_spec;
};
etc...
Or maybe the other way around, that is - embed data type in a storage
class?
I'm aware that it's impossible to help me with so small amount of
information given. Though I hope you can give me some references to
whatever medium, where a remotely similar problem is solved.
Thanks for your time.
Cheers.
I've been pondering with this for quite some time now, and finally
decided to ask here for suggestions. I'm kind of confused, actually...
Maybe I'm thinking too much...
Brain dump follows...
I need a class to represent a variable, with an associated data type
and/or value. Though, I don't want it to be a variant type, and not a
'convenience' class either.
The variable objects will be used in variable lists (a'la symbol tables),
so they are going to be polymorphic.
Now to the point...
The variable type is determined by the following factors:
1. raw data type (int, float, string, etc...)
2. array width (if it's an array of p.1)
3. storage class modifier
My dilemma concerns the actual design of the way how to access those
variables in different parts of the system.
The lists of variables are used in quite different situations.
For example, in generating function prototypes (type declarations),
carrying actual data around the system, translating data coming from
external sources.
The above requirements are pushing me towards a consequent use of the
visitor pattern. Though, I'm completely puzzled on how to apply visitor
to a type which is determined by 3 factors (as shown above).
It all seems as a total maintenance disaster at the moment...
THE Question:
Is there a simple way (or a way to simplify) such a case of three-way-
visitation?
Should I go for explicit definition of each type?
E.g.
Given types Int and Float, and storage classes Uniform and Varying,
define every possible combination of data type, array specifier, and
storage class modifier. ouch!
class Variable ... // the root
class UniformInt : public Variable ...
class UniformIntArray : public Variable ...
class VaryingInt : public Variable ...
class VaryingIntArray : public Variable ...
class UniformFloat : public Variable ...
etc...
Maybe I could nest it in some way?
E.g.
class StorageSpec ... // root
class Uniform : public StorageSpec ...
class Varying : public StorageSpec ...
class Variable ... // root
class Float : public Variable {
StorageSpec* m_storage_spec;
};
etc...
Or maybe the other way around, that is - embed data type in a storage
class?
I'm aware that it's impossible to help me with so small amount of
information given. Though I hope you can give me some references to
whatever medium, where a remotely similar problem is solved.
Thanks for your time.
Cheers.