Skip to content

Commit

Permalink
untested, unused implementation sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
kodebach committed Feb 11, 2021
1 parent 97205a4 commit f2a2b1e
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 531 deletions.
11 changes: 7 additions & 4 deletions examples/gopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern char ** environ;
*
* DO NOT set/unset the specification inside of your application.
*/

/* FIXME: kdbEnsure
static KeySet * createSpec (void)
{
return ksNew (
Expand Down Expand Up @@ -93,6 +93,7 @@ static int setupSpec (void)
return 1;
}
static void removeSpec (void)
{
Key * parentKey = keyNew (SPEC_BASE_KEY, KEY_END);
Expand All @@ -104,15 +105,17 @@ static void removeSpec (void)
kdbSet (kdb, ks, parentKey);
kdbClose (kdb, parentKey);
ksDel (ks);
}
}*/

// -----------------
// Main example
// -----------------

int main (void)
{
if (!setupSpec ())
return EXIT_FAILURE;
// FIXME: update kdbEnsure
/*if (!setupSpec ())
{
fprintf (stderr, "ERROR: Couldn't setup spec, keys exist!\n");
return EXIT_FAILURE;
Expand Down Expand Up @@ -253,5 +256,5 @@ int main (void)
removeSpec ();
return EXIT_SUCCESS;
return EXIT_SUCCESS;*/
}
29 changes: 0 additions & 29 deletions src/bindings/cpp/include/kdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class KDB
virtual inline int set (KeySet & returned, std::string const & keyname);
virtual inline int set (KeySet & returned, Key & parentKey);

inline int ensure (const KeySet & contract, Key & parentKey);

private:
ckdb::KDB * handle; ///< holds an kdb handle
};
Expand Down Expand Up @@ -238,33 +236,6 @@ inline int KDB::set (KeySet & returned, Key & parentKey)
return ret;
}

/**
* Ensures that the conditions defined in @p contract are met by this KDB.
*
* @see ckdb::kdbEnsure()
*
* @param contract The contract to ensure.
* @param parentKey The parentKey to use.
*
* @throw KDBException if there were problems with the contract or the database
* @throw ContractException if the contract couldn't be ensured
*/
int KDB::ensure (const KeySet & contract, Key & parentKey)
{
// have to ksDup because contract is consumed and ksDel()ed by kdbEnsure
int ret = ckdb::kdbEnsure (handle, ckdb::ksDup (contract.getKeySet ()), parentKey.getKey ());
if (ret == -1)
{
throw KDBException (parentKey);
}
if (ret == 1)
{
throw ContractException (parentKey);
}
return ret;
}


} // end of namespace kdb

#endif
9 changes: 5 additions & 4 deletions src/include/kdb.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ typedef struct _KeySet KeySet;
*
**************************************/

KDB * kdbOpen(KeySet * contract, Key *parentKey);
KDB * kdbOpen(const KeySet * contract, Key *parentKey);

// TODO: migrate
static inline KDB * kdbOpenOld (Key * errorKey) {
Expand All @@ -118,9 +118,6 @@ int kdbGet(KDB *handle, KeySet *returned,
int kdbSet(KDB *handle, KeySet *returned,
Key *parentKey);

// TODO: remove
int kdbEnsure (KDB * handle, KeySet * contract, Key * parentKey);


/**************************************
*
Expand Down Expand Up @@ -175,6 +172,8 @@ ssize_t keyGetName(const Key *key, char *returnedName, size_t maxSize);
ssize_t keySetName(Key *key, const char *newname);
ssize_t keyAddName(Key *key, const char *addName);

int keyReplacePrefix (Key * key, const Key * oldPrefix, const Key * newPrefix);

const void *keyUnescapedName(const Key *key);
ssize_t keyGetUnescapedNameSize(const Key *key);

Expand Down Expand Up @@ -242,6 +241,8 @@ Key *ksAtCursor(KeySet *ks, elektraCursor cursor);
Key *ksLookup(KeySet *ks, Key *k, elektraLookupFlags options);
Key *ksLookupByName(KeySet *ks, const char *name, elektraLookupFlags options);

ssize_t ksRename (KeySet *ks, const Key *root, const Key *newRoot);

#ifdef __cplusplus
}
}
Expand Down

0 comments on commit f2a2b1e

Please sign in to comment.