00001 #pragma once
00002
00003 #ifndef NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00004 #define NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00005
00006
00007 namespace YAML
00008 {
00009 template <typename T, typename U>
00010 struct is_same_type {
00011 enum { value = false };
00012 };
00013
00014 template <typename T>
00015 struct is_same_type<T, T> {
00016 enum { value = true };
00017 };
00018
00019 template <typename T, bool check>
00020 struct is_index_type_with_check {
00021 enum { value = false };
00022 };
00023
00024 template <> struct is_index_type_with_check<std::size_t, false> { enum { value = true }; };
00025
00026 #define MAKE_INDEX_TYPE(Type) \
00027 template <> struct is_index_type_with_check<Type, is_same_type<Type, std::size_t>::value> { enum { value = true }; }
00028
00029 MAKE_INDEX_TYPE(int);
00030 MAKE_INDEX_TYPE(unsigned);
00031 MAKE_INDEX_TYPE(short);
00032 MAKE_INDEX_TYPE(unsigned short);
00033 MAKE_INDEX_TYPE(long);
00034 MAKE_INDEX_TYPE(unsigned long);
00035
00036 #undef MAKE_INDEX_TYPE
00037
00038 template <typename T>
00039 struct is_index_type: public is_index_type_with_check<T, false> {};
00040
00041
00042 template <typename T, bool b>
00043 struct _FindFromNodeAtIndex {
00044 const Node *pRet;
00045 _FindFromNodeAtIndex(const Node&, const T&): pRet(0) {}
00046 };
00047
00048 template <typename T>
00049 struct _FindFromNodeAtIndex<T, true> {
00050 const Node *pRet;
00051 _FindFromNodeAtIndex(const Node& node, const T& key): pRet(node.FindAtIndex(static_cast<std::size_t>(key))) {}
00052 };
00053
00054 template <typename T>
00055 inline const Node *FindFromNodeAtIndex(const Node& node, const T& key) {
00056 return _FindFromNodeAtIndex<T, is_index_type<T>::value>(node, key).pRet;
00057 }
00058 }
00059
00060 #endif // NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66