Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip value of certain nodes #840

Open
asuessenbach opened this issue Oct 30, 2024 · 0 comments
Open

Skip value of certain nodes #840

asuessenbach opened this issue Oct 30, 2024 · 0 comments

Comments

@asuessenbach
Copy link

I need to read some json files, not controlled by me. I'm interested in a couple of nodes in those files, and they might be there or not. If they're not there, I'll live with some defaults. And there might be some other nodes I'm not interested in.

To do so, my struct would have a loading function like this:

  template <class Archive>
  void load( Archive & archive )
  {
    do
    {
      char const * name = archive.getNodeName();
      if ( name )
      {
        if ( strcmp( name, "foo" ) == 0 )
        {
          archive( foo );
        }
        else if ( strcmp( name, "bar" ) == 0 )
        {
          archive( bar );
        }
        else
        {
          // ignore all other possible elements here
          archive.skipValue();
        }
      }
    } while ( name );

Near the end, you see a call archive.skipValue();. As far as I know, nothing like that exits.

An implementation in JSONInputArchive would be pretty simple and could look like this:

      void skipValue()
      {
        ++itsIteratorStack.back();
      }

Are there some means available with the current state to achieve such behaviour?
If that's not the case, could such a function be added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant