A
Aleks Dubinskiy
Hi, I have the following programming dilemma:
I need a find a good way to represent matches between contents of
containers.
For example, I have 2 or more an STL deque of feature points.
deque<FeaturePoint> cont1, cont2.
some elements of cont1 map to some elements of cont2 (one-to-one), and the
sizes of the containers are not necessarily the same.
Also we can assume that the containers in question are random access (like
std::deque or std::vector)
I can think of two ways of representing matching:
1) matching addresses / pointers / iterators
This approach is convenient because the matching structure has direct
access to the containers' contents.
But unfortunately, in this scheme it is difficult to serialize / save
the matching to a file, because the addresses are volatile.
2) matching the indices
This approach makes it easy to save matches to a file, but we have to
keep track of the meaning of these indices elsewhere.
Moreover, when the containers are updated, the indices need to be kept
track of as well.
I have encountered this problem several times, and would like a nice generic
solution, which is:
a) Does not depend on the type of the container or data in it
b) Is suitable for serialization
c) Handles changes of elements within the containers gracefully
Has anyone encountered this before? Is there a cookbook solution for this
kind of problem (such as a Design Pattern)? My Gamma et. al. book is not
helping in this case
Cheers,
Aleks
I need a find a good way to represent matches between contents of
containers.
For example, I have 2 or more an STL deque of feature points.
deque<FeaturePoint> cont1, cont2.
some elements of cont1 map to some elements of cont2 (one-to-one), and the
sizes of the containers are not necessarily the same.
Also we can assume that the containers in question are random access (like
std::deque or std::vector)
I can think of two ways of representing matching:
1) matching addresses / pointers / iterators
This approach is convenient because the matching structure has direct
access to the containers' contents.
But unfortunately, in this scheme it is difficult to serialize / save
the matching to a file, because the addresses are volatile.
2) matching the indices
This approach makes it easy to save matches to a file, but we have to
keep track of the meaning of these indices elsewhere.
Moreover, when the containers are updated, the indices need to be kept
track of as well.
I have encountered this problem several times, and would like a nice generic
solution, which is:
a) Does not depend on the type of the container or data in it
b) Is suitable for serialization
c) Handles changes of elements within the containers gracefully
Has anyone encountered this before? Is there a cookbook solution for this
kind of problem (such as a Design Pattern)? My Gamma et. al. book is not
helping in this case
Cheers,
Aleks