CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    13

    Question code to model a group of objects (same type) with many-to-many associations between t

    Hi,

    Does anyone have the code for a class that implements a collection with many-to-many / self-referencing? I'm thinking of a class that houses the collection of objects, and a custom object that represents the actual object (e.g. webfile) that itself has a parent & children list. Anyone what I'm trying to solve is:

    1. Need to model a website which is based on a number of web files (e.g. class = "webfile"),
    2. Model parent & child relationship - In terms of associations a webfile can have multiple child webfiles, and child webfiles can have multiple parents. (think of a HTML page that have multiple images, or multiple HTML pages that share the same image)
    3. A file can be both a parent & a child - or in other words a HTML page can have a link to other HTML pages.
    4. There should be no duplicates anywhere, assume that the URI is the key. In a sense I'm wanting to model the files sitting on a web site. There is only one actual copy of image XYZ, however there will be links to it from multiple pages.
    5. The actual webfile class itself would be key'ed of a unique URI, however I envisage other attributes in the class such as lastmodifieddate, size etc.
    6. Oh, and I was going to use XML serialization on the class as well, to save/load the data. Not sure if this affects the answer
    7. Would like it to support the ability to ask questions such as: "give me children for file XYZ (a Uri would be a good key)", or "addChildToParent(Uri child, Uri parent)"

    Hope this makes sense.

    If anyone has code for this class (or classes, perhaps it would be one container class, and one class that models the webfile?)

    thanks

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: code to model a group of objects (same type) with many-to-many associations betwe

    You could use the std:air class to associate one class with another.
    Code:
    std::pair<class1, class2> p1(obj1, obj2);
    If you need a collection of such associations, create a vector of pairs.
    Code:
    std::vector<std::pair<class1, class2>> v;
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Aug 2007
    Posts
    13

    Re: code to model a group of objects (same type) with many-to-many associations betwe

    oh dear - I've posted in the C++ note the C# area - sorry (couldn't understand your response but then realized)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured