summaryrefslogtreecommitdiff
path: root/tiger-compiler/lib/misc/unique.hxx
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/lib/misc/unique.hxx
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/lib/misc/unique.hxx')
-rw-r--r--tiger-compiler/lib/misc/unique.hxx95
1 files changed, 95 insertions, 0 deletions
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 <misc/contract.hh>
+#include <misc/unique.hh>
+
+namespace misc
+{
+ template <typename T, class C> unique<T, C>::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 T, class C>
+ typename unique<T, C>::object_set_type& unique<T, C>::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 T, class C>
+ typename unique<T, C>::object_size_type unique<T, C>::object_map_size()
+ {
+ // FIXME DONE: Some code was deleted here.
+ return object_set_instance().size();
+ }
+
+ template <typename T, class C>
+ inline const typename unique<T, C>::data_type& unique<T, C>::get() const
+ {
+ // FIXME DONE: Some code was deleted here.
+ return *obj_;
+ }
+
+ template <typename T, class C>
+ inline unique<T, C>::operator const data_type&() const
+ {
+ // FIXME DONE: Some code was deleted here.
+ return *obj_;
+ }
+
+ template <typename T, class C>
+ inline typename unique<T, C>::value_type&
+ unique<T, C>::operator=(const value_type& rhs)
+ {
+ if (this != &rhs)
+ obj_ = rhs.obj_;
+ return *this;
+ }
+
+ template <typename T, class C>
+ inline bool unique<T, C>::operator==(const value_type& rhs) const
+ {
+ return obj_ == rhs.obj_;
+ }
+
+ template <typename T, class C>
+ inline bool unique<T, C>::operator!=(const value_type& rhs) const
+ {
+ return !operator==(rhs);
+ }
+
+ template <typename T, class C>
+ inline bool unique<T, C>::operator<(const value_type& rhs) const
+ {
+ C cmp;
+ assertion(obj_);
+ assertion(rhs.obj_);
+ return cmp(*obj_, *rhs.obj_);
+ }
+
+ template <typename T, class C>
+ inline std::ostream& operator<<(std::ostream& ostr, const unique<T, C>& the)
+ {
+ return ostr << the.get();
+ }
+
+} // namespace misc