Skip to content

Skip value of certain nodes #840

@asuessenbach

Description

@asuessenbach

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions