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

  • Home
  • SEARCH
  • 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 892251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:01:21+00:00 2026-05-15T14:01:21+00:00

I’ll be writing a validator for a specific file format (the format itself is

  • 0

I’ll be writing a validator for a specific file format (the format itself is unimportant). There’s a large set of documents that specify what every section of the format needs to look like, how the different parts relate and so on. Lots and lots of MUST’s, SHALL’s, SHOULD’s, MAY’s etc.

The architecture I envision is as follows: load the document into memory/separate files on disk, and then run numerous validation “passes” on the document: every pass would check for the adherence to one and only one rule specified in the standard, and if the pass fails, an error message is printed to stdout. Every pass would be a separate class implementing a common interface and an instance of each pass would be created on the stack, run on the document and the Result collected (containing error ID, message, line/column number etc). The Results would then be looped over and messages printed out. A unit test could then be easily created for every pass.

Now, I expect to eventually have hundreds of these “pass” classes. And every one of these would need to be instantiated once, run over the document, and the Result collected.

Do you see where I’m going with this? How do I create all these different instances without having a 500 line function that creates each and every one, line by line? I’d like some sort of loop. I’d also like the new pass classes to somehow be “discovered” when created, so I don’t have to manually add lines that instantiate those new classes.

Thinking about it now, all this seems to remind me of unit testing frameworks…

  • 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-05-15T14:01:22+00:00Added an answer on May 15, 2026 at 2:01 pm

    C++ is a static language that lacks reflection, hence you will have to enumerate your classes one way or another, be it a map of class names to factory functions, an explicit function that creates them all, or cppunit-style “registration” (same as putting them in a static map).

    With that said, go with the simplest possible way that’s easiest to change, and does not introduce too much needless work and boilerplate code: creating a list of them in a function.

    You are saying you will have hundreds of them “eventually”, not now. By the time you have hundreds of them, your design will have changed completely. If instantiation of all of them is localised in one function, it will make it easier to change your (uniform) design to add validators that depends on the state of previous validators, add arguments to validator constructors, or replace a simple list of validators with some composite structure, like conditional validators (e.g. run X only if Y had certain result, or run Z if X and Y are enabled).

    Simple code like that is also easier to throw away if it is no longer fit for the task, as you only tend to get invested in a complicated designs and add kludges to it instead of throwing it away. 🙂

    When your codebase matures, you will know exactly what kind of arrangement you need, but for now, do the simplest thing that can possibly work.


    PS

    Use a file-local macro, if typing some_ptr<Foo> foo = new Foo() bothers you, macros aren’t that dirty 🙂

    E. g.

    #define NEW_V(cls, ...) do {\
        std::tr1::shared_ptr<Validator> v(new cls(__VA_ARGS__));\
        lst.push_back(v);\
    } while(0)
    ...
    std::list< std::tr1::shared_ptr<Validator> >
    CreateValidators() {
        std::list< std::tr1::shared_ptr<Validator> > lst;
        CREATE_V(Foo);
        CREATE_V(Bar);
        CREATE_V(Baz, "baz");
        return lst;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.