C and C++ web framework. http://rapida.vilor.one/docs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

120 lines
2.1 KiB

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright 2022 Ivan Polyakov */
#ifndef RAPIDA_KEYVAL_HXX_ENTRY
#define RAPIDA_KEYVAL_HXX_ENTRY
#include "keyval.h"
namespace rpd {
/*!
* \brief C++ wrapper of the key-value pairs storage.
*/
class KeyVal {
public:
/*!
* \brief Default constructor.
*
* Create storage without initial allocation.
*/
KeyVal();
/*!
* \brief Constructor.
*
* \param capacity Initial capacity of this storage.
*/
KeyVal(int capacity);
/*!
* \brief Constructor
*
* \param keyval Base key-value storage (C implementation).
*/
KeyVal(rpd_keyval *keyval)
{
_keyval = keyval;
}
/*!
* \brief Is the storage unique?
*/
bool unique() const
{
return _keyval->unique;
}
/*!
* \brief Sets the uniqueness flag.
*
* \param is_unique Uniqueness flag.
*/
void unique(bool is_unique)
{
_keyval->unique = is_unique;
}
/*!
* \brief Returns real key-value storage.
*
* \return C key-value storage.
*/
rpd_keyval *keyval() const
{
return _keyval;
}
/*!
* \brief Get key-value pairs array.
*
* \return Key-value pairs.
*/
rpd_keyval_item *items() const
{
return _keyval->items;
}
/*!
* \brief Get number of key-value pairs in this storage.
*
* \return Number of entries.
*/
int size() const
{
return _keyval->size;
}
/*!
* \brief Get capacity of this storage (allocated memory);
*
* \return Allocated memory.
*/
int capacity() const
{
return _keyval->capacity;
}
/*!
* \brief Get value of key-value pair by it's key.
*
* \return Value or NULL.
*/
const char *operator[](const char *key)
{
return rpd_keyval_find(_keyval, key)->val;
}
/*!
* \brief Destructor.
*/
virtual ~KeyVal()
{
rpd_keyval_cleanup(_keyval);
}
private:
rpd_keyval *_keyval; //< Composition with C implementation.
};
}
#endif // RAPIDA_KEYVAL_HXX_ENTRY