Files
revng-revng/include/revng/ADT/KeyedObjectTraits.h
Alessandro Di Federico 49287e9de7 Improve Model and TupleTree
This commit:

* Drops `KeyTraits::toString`: if needed, use `getNameFromYAMLScalar`.
* Makes many methods in TupleTree.h return `nullptr` or `std::optional`
  in order to gracefully handle failures.
* Provides `KeyTraits` specializations for integral types and tuple-like
  composed by types providing `KeyTraits`.
* Introduces `CompositeScalar`, which enables tuple-like objects to be
  YAML-serializable scalars by joining the YAML-serialization of its
  members through a customziable character.
* Implements `PathMatcher`, a very simple "regular expression" mechanism
  for paths on tuple trees.
* Introduce testing for the Model.
2021-02-17 11:48:46 +01:00

28 lines
649 B
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "revng/ADT/KeyTraits.h"
#include "revng/ADT/STLExtras.h"
template<typename T, typename = void>
struct KeyedObjectTraits {
// static * key(const T &);
// static T fromKey(* Key);
};
/// Inherit if T is the key of itself
template<typename T>
struct IdentityKeyedObjectTraits {
static T key(const T &Obj) { return Obj; }
static T fromKey(T Obj) { return Obj; }
};
/// Trivial specialization for integral types
template<typename T>
struct KeyedObjectTraits<T, enable_if_is_integral_t<T>>
: public IdentityKeyedObjectTraits<T> {};