# safe-object **Repository Path**: tizzybec/safe-object ## Basic Information - **Project Name**: safe-object - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-06-03 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # safe-object safe-object是针对安全对象开发的安全类,受到了boost::enable_shared_from_this的其他,能够解决非智能指针类型的安全引用问题,safe-object 提供两种类型的安全对象,基于存活和基于引用,基于引用的方式下,每次引用会增加一次引用,使用完成会减少一次引用,在特定情况下基于引用的方式可以退化成基于存活的方式。 ## 依赖 - boost - std(c++11) - gtest ## 使用说明 ```C++ #include class TestClass : public tb::safe::Object { ... ~TestClass() { // normally you do not need do any thing // if you try to destroy the instance call TryDie this->TryDie(); // if you want force destroy the instance call ForceDie this->WaitAndForceDie(); } void DoSomeThing(int a, int b) { ... } void InvokeAsyncCall() { ThreadPool::Instance()->Post( Bind(TestClass::DoSomeThing, this, 1, 2); ); } }; // or a ref count version class TestClass : public tb::safe::RefCountObject { ... ~TestClass() { // normally you do not need do any thing // if you try to destroy the instance call TryDie this->TryDie(); // if you want force destroy the instance call ForceDie, // it will ignore the reference count, all the post task will be invalid this->WaitAndForceDie(); } void DoSomeThing(int a, int b) { ... } void InvokeAsyncCall() { ThreadPool::Instance()->Post( Bind(TestClass::DoSomeThing, this, 1, 2); ); } }; ``` ## 联系 author: tizzybec gitee: tizzybec email: tizzybec@outlook.com