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