diff options
| -rw-r--r-- | src/cc4group.c | 8 | ||||
| -rw-r--r-- | src/cc4group.h | 6 | ||||
| -rw-r--r-- | src/cppc4group.cpp | 7 | ||||
| -rw-r--r-- | src/cppc4group.hpp | 1 |
4 files changed, 19 insertions, 3 deletions
diff --git a/src/cc4group.c b/src/cc4group.c index 5cbce53..c1c434a 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -3289,6 +3289,11 @@ static CC4Group* cc4group_openAsChild(CC4Group* const this, const char* const pa return child; } +static bool cc4group_isChild(const CC4Group* const this) +{ + return this->parent != NULL; +} + static void* cc4group_memoryManagementTakeStart(void* const data, size_t const size, void* const arg) { (void)size; @@ -3436,5 +3441,6 @@ CC4Group_API cc4group = { .getErrorCauser = cc4group_getErrorCauser, - .openAsChild = cc4group_openAsChild + .openAsChild = cc4group_openAsChild, + .isChild = cc4group_isChild }; diff --git a/src/cc4group.h b/src/cc4group.h index 8de4616..732aa0c 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -29,7 +29,7 @@ // the directory separator used for all entry paths in cc4group is "/" _regardless of the platform_. yes, you better watch out Windows users! // in contrast to paths names are only the the name of the entry itself, not the whole path // - to free all resources used by the group when it is not needed anymore, call cc4group.delete with the group pointer and discard it afterwards (i.e. don't use it anymore) -// - all functions, except cc4group.new, cc4group.setLazy, cc4group.openAsChild, cc4group.delete, cc4group.setWarningCallback and cc4group.setTmpMemoryStrategy (where the latter three can't fail) follow the same scheme +// - all functions, except cc4group.new, cc4group.setLazy, cc4group.openAsChild, cc4group.isChild, cc4group.delete, cc4group.setWarningCallback and cc4group.setTmpMemoryStrategy (where the latter three can't fail) follow the same scheme // all of them can fail, either caused by wrong arguments or by things outside of the applications control // they all return _true_ if everything went well and _false_ if any error occured // information about the error (incredibly useful for debugging or asking for help with problems) can be obtained by using one of the cc4group.getError* functions @@ -430,6 +430,10 @@ typedef struct { // cc4group.saveParent saves the top-most parent with cc4group.save in order to save the changes in the child to disk. this will also save modifications made inside the parent group... // ...outside of this children CC4Group* (*openAsChild)(CC4Group* const this, const char* const path); + + // returns wether this group has been opend with cc4group.openAsChild + // NOTE: this function can't fail, thus the return value is the result value, not the success indication + bool (*isChild)(const CC4Group* const this); } const CC4Group_API; diff --git a/src/cppc4group.cpp b/src/cppc4group.cpp index 4db6153..31dab62 100644 --- a/src/cppc4group.cpp +++ b/src/cppc4group.cpp @@ -486,4 +486,9 @@ std::optional<CppC4Group> CppC4Group::openAsChild(const std::string& path) { return {{std::make_unique<Private>(g)}}; } -}
\ No newline at end of file +} + +bool CppC4Group::isChild() +{ + return cc4group.isChild(p->g); +} diff --git a/src/cppc4group.hpp b/src/cppc4group.hpp index 33cf2cc..7ede7ae 100644 --- a/src/cppc4group.hpp +++ b/src/cppc4group.hpp @@ -193,6 +193,7 @@ public: // to get the child group out of the optional in case of success, construct a new CppC4Group with the move constructor: CppC4Group child{std::move(*optionalChild)}; std::optional<CppC4Group> openAsChild(const std::string& path); + bool isChild(); }; inline bool operator&(CppC4Group::AllowedEntryTypes lhs, CppC4Group::AllowedEntryTypes rhs) |
