Browse Source

using std::shared_ptr is too complicated for this.

heck-rework
heck 3 years ago
parent
commit
3b556c2e99
  1. 25
      test/test_nr1.cc

25
test/test_nr1.cc

@ -86,6 +86,8 @@ namespace pEp {
// set() can only be called once, will throw otherwise.
class String {
public:
// Usually you _have_ to use this ctor, because its impossible to create a static
// object if you have to know the address of a dynamically created one.
String() = default;
// Best to use this constructor, as the object is in a valid state when the wrapped
@ -112,9 +114,7 @@ namespace pEp {
// init
_c_str_pp = c_str_pp;
// _c_str_p.reset(*_c_str_pp, [&](char* ptr) { this->_free(ptr); });
_c_str_p = *_c_str_pp;
_is_initialized = true;
pEpLogClass(to_string() + " - taking ownership");
}
@ -129,31 +129,14 @@ namespace pEp {
// DEALLOCATION
_free();
// // if we point to an initialized string
// if (*_c_str_pp != nullptr) {
// // if the string there is not the one we created
//// if (*_c_str_pp != _c_str_p.get()) {
// if (*_c_str_pp != _c_str_p) {
// // we need to free it before we lose the pointer to it
// pEpLog("freeing foreign allocated string");
// pEp::free(*_c_str_pp);
// // } // else it will be free automatically upon .reset()
// }
// //and we need to anyways free the strings we create ourselfes
// if
// pEp::free(_c_str_p;)
// }
// ALLOCATION
if (str.empty()) {
// if the new value is empty str, lets point to nothing
*_c_str_pp = nullptr;
// _c_str_p.reset(*_c_str_pp);
_c_str_p = *_c_str_pp;
} else {
*_c_str_pp = pEp::alloc(str);
// _c_str_p.reset(*_c_str_pp, [&](char* ptr) { this->_free(ptr); });
_c_str_p = *_c_str_pp;
}
pEpLogClass("After: " + to_string());
@ -198,7 +181,6 @@ namespace pEp {
static bool log_enabled;
private:
void _free()
{
@ -219,7 +201,6 @@ namespace pEp {
bool _is_initialized{ false };
char** _c_str_pp{ nullptr };
// std::shared_ptr<char> _c_str_p{};
char* _c_str_p{ nullptr };
Adapter::pEpLog::pEpLogger logger{ "pEp::String", log_enabled };
@ -324,7 +305,7 @@ void test_getters(char const* const* const c_str_p, pEp::String& pstr)
} else {
std::string tmp{ pstr };
pEpLog("operator std::string(): " + tmp);
assert(tmp == "");
assert(tmp.empty());
}
}

Loading…
Cancel
Save