Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 205999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:36:23+00:00 2026-05-11T17:36:23+00:00

I’ve been batting this problem around in my head for a few days now

  • 0

I’ve been batting this problem around in my head for a few days now and haven’t come to any satisfactory conclusions so I figured I would ask the SO crew for their opinion. For a game that I’m working on I’m using a Component Object Model as described here and here. It’s actually going fairly well but my current storage solution is turning out to be limiting (I can only request components by their class name or an arbitrary “family” name). What I would like is the ability to request a given type and iterate through all components of that type or any type derived from it.

In considering this I’ve first implemented a simple RTTI scheme that stores the base class type through the derived type in that order. This means that the RTTI for, say, a sprite would be: component::renderable::sprite. This allows me to compare types easily to see if type A is derived from type B simply by comparing the all elements of B: i.e. component::renderable::sprite is derived from component::renderable but not component::timer. Simple, effective, and already implemented.

What I want now is a way to store the components in a way that represents that hierarchy. The first thing that comes to mind is a tree using the types as nodes, like so:

       component
       /       \
  timer         renderable
  /              /      \
shotTimer   sprite      particle

At each node I would store a list of all components of that type. That way requesting the “component::renderable” node will give me access to all renderable components regardless of derived type. The rub is that I want to be able to access those components with an iterator, so that I could do something like this:

for_each(renderable.begin(), renderable.end(), renderFunc);

and have that iterate over the entire tree from renderable down. I have this pretty much working using a really ugly map/vector/tree node structure and an custom forward iterator that tracks a node stack of where I’ve been. All the while implementing, though, I felt that there must be a better, clearer way… I just can’t think of one 🙁

So the question is: Am I over-complicating this needlessly? Is there some obvious simplification I’m missing, or pre-existing structure I should be using? Or is this just inheritly a complex problem and I’m probably doing just fine already?

Thanks for any input you have!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:36:23+00:00Added an answer on May 11, 2026 at 5:36 pm

    You should think about how often you need to do the following:

    • traverse the tree
    • add/remove elements from the tree
    • how many objects do you need to keep track of

    Which is more frequent will help determine the optimum solution

    Perhaps instead of make a complex tree, just have a list of all types and add a pointer to the object for each type it is derived from. Something like this:

    map<string,set<componenet *>>  myTypeList
    

    Then for an object that is of type component::renderable::sprite

    myTypeList["component"].insert(&object);
    myTypeList["renderable"].insert(&object);
    myTypeList["sprite"].insert(&object);
    

    By registering each obejct in multiple lists, it then becomes easy to do something to all object of a given type and subtypes

    for_each(myTypeList["renderable"].begin(),myTypeList["renderable"].end(),renderFunc);
    

    Note that std::set and my std::map construct may not be the optimum choice, depending on how you will use it.

    Or perhaps a hybrid approach storing only the class heirarchy in the tree

    map<string, set<string> > myTypeList;
    map<string, set<component *> myObjectList;
    
    myTypeList["component"].insert("component");
    myTypeList["component"].insert("renderable");
    myTypeList["component"].insert("sprite");
    myTypeList["renderable"].insert("renderable");
    myTypeList["renderable"].insert("sprite");
    myTypeList["sprite"].insert("sprite");
    
    // this isn't quite right, but you get the idea
    struct doForList {
        UnaryFunction f;
        doForList(UnaryFunction f): func(f) {};
        operator ()(string typename) { 
           for_each(myTypeList[typename].begin();myTypeList[typename].end(), func);
       }
    }
    
    for_each(myTypeList["renderable"].begin(),myTypeList["renderable"].end(), doForList(myFunc))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.