YAML 根节点 !Null 但大小为 0
YAML root node !Null but size is 0
我是 YAML 的新手,正在尝试举个例子 运行。我有来自 http://www.gamedev.net/page/resources/_/technical/apis-and-tools/yaml-basics-and-parsing-with-yaml-cpp-r3508 的 Sprites_list YAML 文件并且 root/base 节点始终不是 Null 但大小始终为 0,类型为标量,并且尝试访问节点会抛出 YAML::BadSubscript 异常。 Yaml 0.5.3 impl.h 中的第 118 行。为什么根节点的大小为 0,为什么无法访问节点?
YAML::Node root_node_ = YAML::Load( file );
if( root_node_.IsNull() )
{
// Never entered
}
int sz = root_node_.size(); // Always 0
YAML::Node a_node = root_node_[ "Sprites_List" ]; // Exception
编辑-->
完整文件内容(粘贴到名为 sprites.yml 的文件中)
Sprites_List: [Player, Monster, Gem]
Player:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [run, idle, jump, die]
run:
Offset: {x: 0, y: 0}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
idle:
Offset: {x: 0, y: 32}
Size: {w: 32, h: 32}
Frame_Durations: [80, 120, 80, 30, 30, 130] #Notice the different durations!
jump:
Offset: {x: 0, y: 64}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 120, 80, 80, 0] #Can I say 0 mean no skipping?
die:
Offset: {x: 0, y: 192} #192? Yup, it is the last row in that sheet.
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80] #this one has only 5 frames.
Monster: #lol that lam nam
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [hover, die]
hover:
Offset: {x: 0, y: 128}
Size: {w: 32, h: 32}
Frame_Durations: [120, 80, 120, 80]
die:
Offset: {x: 0, y: 160}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80]
Gem:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [shine]
shine:
Offset: {x: 0, y: 96}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
在class声明中-
YAML::Node root_node_;
在class定义中-
CConfigFile( std::string const & file ) :
root_node_ ( YAML::Load( file ) )
文件路径是完整的绝对路径,每个\都用\\转义了。
YAML::Load
加载 YAML 字符串,而不是文件。要加载文件,您需要使用 YAML::LoadFile
.
我是 YAML 的新手,正在尝试举个例子 运行。我有来自 http://www.gamedev.net/page/resources/_/technical/apis-and-tools/yaml-basics-and-parsing-with-yaml-cpp-r3508 的 Sprites_list YAML 文件并且 root/base 节点始终不是 Null 但大小始终为 0,类型为标量,并且尝试访问节点会抛出 YAML::BadSubscript 异常。 Yaml 0.5.3 impl.h 中的第 118 行。为什么根节点的大小为 0,为什么无法访问节点?
YAML::Node root_node_ = YAML::Load( file );
if( root_node_.IsNull() )
{
// Never entered
}
int sz = root_node_.size(); // Always 0
YAML::Node a_node = root_node_[ "Sprites_List" ]; // Exception
编辑--> 完整文件内容(粘贴到名为 sprites.yml 的文件中)
Sprites_List: [Player, Monster, Gem]
Player:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [run, idle, jump, die]
run:
Offset: {x: 0, y: 0}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
idle:
Offset: {x: 0, y: 32}
Size: {w: 32, h: 32}
Frame_Durations: [80, 120, 80, 30, 30, 130] #Notice the different durations!
jump:
Offset: {x: 0, y: 64}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 120, 80, 80, 0] #Can I say 0 mean no skipping?
die:
Offset: {x: 0, y: 192} #192? Yup, it is the last row in that sheet.
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80] #this one has only 5 frames.
Monster: #lol that lam nam
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [hover, die]
hover:
Offset: {x: 0, y: 128}
Size: {w: 32, h: 32}
Frame_Durations: [120, 80, 120, 80]
die:
Offset: {x: 0, y: 160}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80]
Gem:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [shine]
shine:
Offset: {x: 0, y: 96}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
在class声明中-
YAML::Node root_node_;
在class定义中-
CConfigFile( std::string const & file ) :
root_node_ ( YAML::Load( file ) )
文件路径是完整的绝对路径,每个\都用\\转义了。
YAML::Load
加载 YAML 字符串,而不是文件。要加载文件,您需要使用 YAML::LoadFile
.