YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ValueNode.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2012 - 2013.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #include "YSLib/Core/ValueNode.h"
29 
31 
32 bool
33 ValueNode::operator+=(const ValueNode& node)
34 {
35  return CheckNodes().insert(node).second;
36 }
37 bool
38 ValueNode::operator+=(ValueNode&& node)
39 {
40  // TODO: Use %emplace.
41  return CheckNodes().insert(std::move(node)).second;
42 }
43 
44 bool
45 ValueNode::operator-=(const ValueNode& node)
46 {
47  const auto p_con(GetContainerPtr());
48 
49  return p_con ? p_con->erase({0, node.name}) != 0 : false;
50 }
51 
52 const ValueNode&
53 ValueNode::operator[](const string& name) const
54 {
55  auto& cont(CheckNodes());
56  auto i(cont.lower_bound({0, name}));
57 
58  if(i == cont.end() || cont.key_comp()({0, name}, *i))
59  // TODO: Use %emplace_hint.
60  i = cont.insert(i, {0, name});
61  return *i;
62 }
63 
64 const ValueNode&
65 ValueNode::GetNode(const string& name) const
66 {
67  return AccessNode(GetContainer(), name);
68 }
69 size_t
70 ValueNode::GetSize() const ynothrow
71 {
72  const auto p_con(GetContainerPtr());
73 
74  return p_con ? p_con->size() : 0;
75 }
76 
78 ValueNode::CheckNodes() const
79 {
80  if(!Value)
81  Value = Container();
82  return GetContainer();
83 }
84 
85 
86 const ValueNode&
87 AccessNode(const ValueNode::Container& con, const string& name)
88 {
89  return ystdex::at(con, ValueNode(0, name));
90 }
91 
92 YSL_END
93