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 7989179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:40:44+00:00 2026-06-04T12:40:44+00:00

I am designing an application, where multiple geometric primitive types (all inheriting the base

  • 0

I am designing an application, where multiple geometric primitive types (all inheriting the base Primitive class) are stored in an object of class Scene.

Instead of having a function in my main() that programmatically creates a scene by constructing the primitives and then calling Scene::add(...), I’d like to have some sort of configuration file that is read at runtime.
This would save me from having to recompile every time I change something about the scene, and seems like a general good idea (in case someone else that can’t program might need to use my program sometime)

I’ve devised a little scheme that defines the scene through a .ini file like so:

[primitivefoo]
type = sphere
pos = 10 20 30
radius = 5.5

[primitivebar]
type = triangle
vertexA = 10 10 -10
vertexB = ...
...

You get the idea.

My plan is to have each subclass of Primitive register their own method interpretINI(...) in the class Scene. Scene would need some sort of map that maps string->void* (...), so that I know which type-string from the .ini file corresponds to which subclass of Primitive.

If this entire approach is bad design, and there is already a much more elegant way to achieve what I want to achieve, I would love to hear it. If not, I would be very grateful if someone could help me realize my design. I’m stuck on how to iterate over all Primitive subclasses to have them register themselves in Scene…

  • 1 1 Answer
  • 0 Views
  • 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-06-04T12:40:46+00:00Added an answer on June 4, 2026 at 12:40 pm

    Your approach sounds good to me, with the exception that the names should map to a function returning Primitive* (instead of void*). This is a factory pattern (on two levels)

    One limitation of this approach is that the factory functions registered will have to accept the same number/type of parameters. [Update: upon reading your comment to your question, this should not be a problem in your case].

    I do not know of any automatic way of enumerating subclasses of a particular class, you will need to manually register the known classes (in main, or a special register function)

    Update: you could get around the subclass enumeration by using static variables (in-class or otherwise) that will run a “register” function specific to the class-in-question:

    class MyShape : public Shape
    {
      static int reg;
      // appropriate constructor
    };
    
    int registerMyShape();
    
    int MyShape::reg = registerMyShape(); // this will be called at program startup
    

    The only problem is, there is no guarantee about the static initialization order in separate compilation units. Maybe if you can make the shapes module-like and “load” them after the registry class is fully initialized?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When designing a new application/database for multiple users, it usually involves having a table
I am designing an application that needs to save geometric shapes in a database.
I am designing an application where a user places multiple UIImageViews one over another.
I am designing a networked embedded application, that can span multiple machines. The applications
I'm designing a desktop application with multiple layers: the GUI layer (WinForms MVP) holds
I am in the process of designing a web application which will have multiple
I am designing an simulator application where the application launches multiple socket connection(around 1000
I am looking into designing an application that can run on multiple platforms (i.e.
I have this task of designing a new interface for a distributed application (multiple
I'm designing an application that will benefit from having the user's Facebook friends suggested

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.