From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/lib/misc/unique.hxx | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tiger-compiler/lib/misc/unique.hxx (limited to 'tiger-compiler/lib/misc/unique.hxx') diff --git a/tiger-compiler/lib/misc/unique.hxx b/tiger-compiler/lib/misc/unique.hxx new file mode 100644 index 0000000..a8560fa --- /dev/null +++ b/tiger-compiler/lib/misc/unique.hxx @@ -0,0 +1,95 @@ +/** + ** \file misc/unique.hxx + ** \brief Inline implementation of misc::unique. + */ + +#pragma once + +#include +#include + +namespace misc +{ + template unique::unique(const data_type& s) + // FIXME DONE: Some code was deleted here (Initializations). + /** \brief Following the Flyweight design pattern, set the attribute to a + unique reference of value s. You might want to check out std::set methods + on cppreference.com. */ + { + if (object_set_instance().insert(s).second) + { + obj_ = &(*(object_set_instance().find(s))); + } + else + { + obj_ = &(*(object_set_instance().find(s))); + } + } + + template + typename unique::object_set_type& unique::object_set_instance() + { + // FIXME DONE: Some code was deleted here (Classical Singleton pattern, a la Scott Meyers'). + /** \brief Create a persistent instance of a set which would hold each value. */ + static object_set_type res{}; + return res; + } + + template + typename unique::object_size_type unique::object_map_size() + { + // FIXME DONE: Some code was deleted here. + return object_set_instance().size(); + } + + template + inline const typename unique::data_type& unique::get() const + { + // FIXME DONE: Some code was deleted here. + return *obj_; + } + + template + inline unique::operator const data_type&() const + { + // FIXME DONE: Some code was deleted here. + return *obj_; + } + + template + inline typename unique::value_type& + unique::operator=(const value_type& rhs) + { + if (this != &rhs) + obj_ = rhs.obj_; + return *this; + } + + template + inline bool unique::operator==(const value_type& rhs) const + { + return obj_ == rhs.obj_; + } + + template + inline bool unique::operator!=(const value_type& rhs) const + { + return !operator==(rhs); + } + + template + inline bool unique::operator<(const value_type& rhs) const + { + C cmp; + assertion(obj_); + assertion(rhs.obj_); + return cmp(*obj_, *rhs.obj_); + } + + template + inline std::ostream& operator<<(std::ostream& ostr, const unique& the) + { + return ostr << the.get(); + } + +} // namespace misc -- cgit v1.2.3