|
Boost Users : |
From: hicks (hicks_at_[hidden])
Date: 2002-03-30 20:41:19
Hello
class RuntimeAssoc
{
std::map<Emp, Mgr>
std:::multimap<Mgr,Emp>
public:
insert(const Mgr&, const Emp&);
std::pair<Mgr, Emp> find(const Mgr&);
std::pair<Emp, Mgr> find(const Emp&);
};
I am not sure what you mean by "direct". Do you mean compile time?
The STL provides an easy way to implement mutable associations at run
time (as shown above);
There was an intersting article in C++ User's Journal last year
containing an implemetation
of a many-to-many mapping class.
I think a "specific" example of what you want to do would be helpful.
Craig Hicks
KGK Ltd
rzako23 wrote:
>Are there any generic components in Boost (or elsewhere) for *directly*
>representing associations between classes?
>
>Generalization, composition, aggregation and association are major
>ideas in the object model. Generalization can be implemented fairly
>directly in C++ using inheritance. Composition and aggregation can be
>represented directly in C++ using data members (when the number of
>parts in each whole is small and fixed), or using STL containers (when
>the number of parts in each whole is large or variable). But Standard
>C++ (including the STL) provides no *direct* support for representing
>associations, i.e., collections of links between objects in two or more
>classes. (David Papurt makes this point in "Inside the Object Model:
>The Sensible Use of C++.")
>
>For example, the STL does not offer a way to *directly* represent the
>1-to-many "Supervises" association from the Manager class to the
>Employee class. One would like to have links in both directions:
>forward links forthe employees a manager supervises and a back link to
>the manager each employee is supervised by. Of course, one could code
>this all "by hand" using a container of pointers to employees for each
>manager and a back pointer for each employee. But the implementation
>details really have little to do with managers and employees and would
>be pretty much the same for parents and children or teachers and
>students. Moreover, while not difficult, managing the forward and back
>links correctly (and in an exception-safe manner) is tedious. It would
>be nice to have templates that can be instantiated to implement
>specific associations.
>
>In brief, STL containers directly support composition and aggregation
>but not association.
>
>I am new to the Boost library, but was not able to find this capability
>in Boost. If an association library is available in Boost (or
>elsewhere), I would be happy to know so.
>
>If not, is an association library something that would be worth looking
>into?
>
>Thanks,
>Rob Zako
>
>
>
>
>
>Info: <http://www.boost.org>
>Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
>Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net