From d31d3df72e12ccee90a5564b1ed5338575ebd699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Fri, 13 Mar 2015 17:12:47 +0800 Subject: [PATCH] add ref --- TinySTL/Detail/Ref.h | 42 +++++++++++++++++++++++++++++++++ TinySTL/TinySTL.vcxproj | 1 + TinySTL/TinySTL.vcxproj.filters | 3 +++ 3 files changed, 46 insertions(+) create mode 100644 TinySTL/Detail/Ref.h diff --git a/TinySTL/Detail/Ref.h b/TinySTL/Detail/Ref.h new file mode 100644 index 0000000..9f22598 --- /dev/null +++ b/TinySTL/Detail/Ref.h @@ -0,0 +1,42 @@ +#ifndef _REF_H_ +#define _REF_H_ + +#include + +namespace TinySTL{ + namespace Detail{ + template + struct ref_t{ + std::atomic ncount_; + T *data_; + + explicit ref_t(size_t n = 0, T *p = nullptr) :ncount_(n), data_(p){} + ref_t(const ref_t&) = default; + ref_t& operator = (const ref_t&) = default; + + size_t count()const{ return ncount_.load(); } + T *get_data()const{ return data_; } + + ref_t& operator ++(){ + ++ncount_; + return *this; + } + ref_t operator ++(int){ + auto t = *this; + ++*this; + return t; + } + ref_t& operator --(){ + --ncount_; + return *this; + } + ref_t operator --(int){ + auto t = *this; + --*this; + return t; + } + }; + } +} + +#endif \ No newline at end of file diff --git a/TinySTL/TinySTL.vcxproj b/TinySTL/TinySTL.vcxproj index 5bebb18..8ed7924 100644 --- a/TinySTL/TinySTL.vcxproj +++ b/TinySTL/TinySTL.vcxproj @@ -121,6 +121,7 @@ + diff --git a/TinySTL/TinySTL.vcxproj.filters b/TinySTL/TinySTL.vcxproj.filters index 88f8c9e..a452549 100644 --- a/TinySTL/TinySTL.vcxproj.filters +++ b/TinySTL/TinySTL.vcxproj.filters @@ -263,6 +263,9 @@ Test + + Detail +