majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Is this problem of specification? #268

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.I want to read yaml as follows,

layer1_1:
  layer2_1: hello
  layer2_2: world
  layer2_3:
    layer_3-1: 1
    layer_3-2: 2

layer1-2:
  layer2_1: hello
  layer2_2: world

2.In order to convert data in yaml perser to my own container,
  I list the items in the second layer as follow, 

     YAML::Node document = YAML::LoadFile(path.c_str());
     const YAML::Node &node = document[root_key][second_key];

     for (YAML::const_iterator itr(node.begin()), end(node.end()); 
                                                        itr != end; ++itr) {
          const YAML::Node& key = itr->first;
          list.push_back(key.as<std::string>());
       }

     Of cause, the structure is assumed to be unknown.
     And, if the item name "layer2_3", which has actually certain name  such as "map_data", is detected, another rutine is called in my program.  

3. The program works succesfully works, but, I got error messages
as follows,

yaml-cpp: error at line 0, column 0: bad conversion

For the data of "layer1-2", the error messages are not displayed.

The reason of error may come from the difference of the type of layer2-2 amd 
layer2-3, i.e. just a string and map of string and integer.

What is the expected output? What do you see instead?

Similar usage may be often used because generally the structure is unknown. How 
can I wipe out these messages.
Is my usage agenst the specification of yaml?

What version of the product are you using? On what operating system?
version 0.5.1

Please provide any additional information below.
none

Original issue reported on code.google.com by chiba...@gmail.com on 23 Dec 2014 at 3:01

GoogleCodeExporter commented 9 years ago
I'm not entirely sure what you mean. Based on your code, it looks like you're 
trying to iterate through some nodes that are not sequence nodes. Dependeing on 
what `root_key` and `second_key` are, `document[root_key][second_key]` may be a 
scalar or a sequence.

You can always check the type of a node by `node.Type()` or, e.g., 
`node.IsScalar()`.

Original comment by jbe...@gmail.com on 24 Dec 2014 at 6:20

GoogleCodeExporter commented 9 years ago
Thank you for your reply.

Indeed, your point out is correct.

The error occures in another part from I described before.
And, I iterated nodes which include both of scalar and sequence
as you pointed out.

By the way, I realised here is not for QA.
I do not mind if you remove this ticket.

I belive this library is very useful and should become standard like GNU works.
But, I do not like the licence of GNU.

I hope this project contenues forever.
Sincerly. 

Original comment by chiba...@gmail.com on 1 Jan 2015 at 4:59

GoogleCodeExporter commented 9 years ago
Thank you!

Original comment by jbe...@gmail.com on 1 Jan 2015 at 7:53