Convert SimpleStringDictionary interface documentation to Doxygen.

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/499643002
This commit is contained in:
Mark Mentovai 2014-08-22 17:09:03 -04:00
parent 4004e77ee9
commit d0fcfa42e4

View File

@ -27,39 +27,50 @@ namespace crashpad {
// using one of the constructors. // using one of the constructors.
struct SerializedSimpleStringDictionary; struct SerializedSimpleStringDictionary;
// TSimpleStringDictionary is an implementation of a map/dictionary collection //! \brief A map/dictionary collection implementation using a fixed amount of
// that uses a fixed amount of storage, so that it does not perform any dynamic //! storage, so that it does not perform any dynamic allocations for its
// allocations for its operations. //! operations.
// //!
// The actual map storage (the Entry) is guaranteed to be POD, so that it can be //! The actual map storage (TSimpleStringDictionary::Entry) is guaranteed to be
// transmitted over various IPC mechanisms. //! POD, so that it can be transmitted over various IPC mechanisms.
// //!
// The template parameters control the amount of storage used for the key, //! The template parameters control the amount of storage used for the key,
// value, and map. The KeySize and ValueSize are measured in bytes, not glyphs, //! value, and map. The \a KeySize and \a ValueSize are measured in bytes, not
// and includes space for a \0 byte. This gives space for KeySize-1 and //! glyphs, and include space for a trailing `NUL` byte. This gives space for
// ValueSize-1 characters in an entry. NumEntries is the total number of entries //! `KeySize - 1` and `ValueSize - 1` characters in an entry. \a NumEntries is
// that will fit in the map. //! the total number of entries that will fit in the map.
template <size_t KeySize = 256, size_t ValueSize = 256, size_t NumEntries = 64> template <size_t KeySize = 256, size_t ValueSize = 256, size_t NumEntries = 64>
class TSimpleStringDictionary { class TSimpleStringDictionary {
public: public:
// Constant and publicly accessible versions of the template parameters. //! \brief Constant and publicly accessible versions of the template
//! parameters.
//! \{
static const size_t key_size = KeySize; static const size_t key_size = KeySize;
static const size_t value_size = ValueSize; static const size_t value_size = ValueSize;
static const size_t num_entries = NumEntries; static const size_t num_entries = NumEntries;
//! \}
// An Entry object is a single entry in the map. If the key is a 0-length //! \brief A single entry in the map.
// NUL-terminated string, the entry is empty.
struct Entry { struct Entry {
//! \brief The entrys key.
//!
//! If this is a 0-length `NUL`-terminated string, the entry is inactive.
char key[KeySize]; char key[KeySize];
//! \brief The entrys value.
char value[ValueSize]; char value[ValueSize];
//! \brief Returns the validity of the entry.
//!
//! If #key is an empty string, the entry is considered inactive, and this
//! method returns `false`. Otherwise, returns `true`.
bool is_active() const { bool is_active() const {
return key[0] != '\0'; return key[0] != '\0';
} }
}; };
// An Iterator can be used to iterate over all the active entries in a //! \brief An iterator to traverse all of the active entries in a
// TSimpleStringDictionary. //! TSimpleStringDictionary.
class Iterator { class Iterator {
public: public:
explicit Iterator(const TSimpleStringDictionary& map) explicit Iterator(const TSimpleStringDictionary& map)
@ -67,8 +78,8 @@ class TSimpleStringDictionary {
current_(0) { current_(0) {
} }
// Returns the next entry in the map, or NULL if at the end of the //! \brief Returns the next entry in the map, or `NULL` if at the end of the
// collection. //! collection.
const Entry* Next() { const Entry* Next() {
while (current_ < map_.num_entries) { while (current_ < map_.num_entries) {
const Entry* entry = &map_.entries_[current_++]; const Entry* entry = &map_.entries_[current_++];
@ -99,8 +110,8 @@ class TSimpleStringDictionary {
return *this; return *this;
} }
// Constructs a map from its serialized form. |map| should be the out //! \brief Constructs a map from its serialized form. \a map should be the out
// parameter from Serialize() and |size| should be its return value. //! parameter from Serialize(), and \a size should be its return value.
TSimpleStringDictionary( TSimpleStringDictionary(
const SerializedSimpleStringDictionary* map, size_t size) { const SerializedSimpleStringDictionary* map, size_t size) {
DCHECK_EQ(size, sizeof(entries_)); DCHECK_EQ(size, sizeof(entries_));
@ -109,8 +120,8 @@ class TSimpleStringDictionary {
} }
} }
// Returns the number of active key/value pairs. The upper limit for this is //! \brief Returns the number of active key/value pairs. The upper limit for
// NumEntries. //! this is \a NumEntries.
size_t GetCount() const { size_t GetCount() const {
size_t count = 0; size_t count = 0;
for (size_t i = 0; i < num_entries; ++i) { for (size_t i = 0; i < num_entries; ++i) {
@ -121,8 +132,12 @@ class TSimpleStringDictionary {
return count; return count;
} }
// Given |key|, returns its corresponding |value|. |key| must not be NULL. If //! \brief Given \a key, returns its corresponding value.
// the key is not found, NULL is returned. //!
//! \param[in] key The key to look up. This must not be `NULL`.
//!
//! \return The corresponding value for \a key, or if \a key is not found,
//! `NULL`.
const char* GetValueForKey(const char* key) const { const char* GetValueForKey(const char* key) const {
DCHECK(key); DCHECK(key);
if (!key) { if (!key) {
@ -137,10 +152,15 @@ class TSimpleStringDictionary {
return entry->value; return entry->value;
} }
// Stores |value| into |key|, replacing the existing value if |key| is already //! \brief Stores \a value into \a key, replacing the existing value if \a key
// present. |key| must not be NULL. If |value| is NULL, the key is removed //! is already present.
// from the map. If there is no more space in the map, then the operation //!
// silently fails. //! If there \a key is not yet in the map and the map is already full
//! (containing \a NumEntries active entries), this operation silently fails.
//!
//! \param[in] key The key to store. This must not be `NULL`.
//! \param[in] value The value to store. If `NULL`, \a key is removed from the
//! map.
void SetKeyValue(const char* key, const char* value) { void SetKeyValue(const char* key, const char* value) {
if (!value) { if (!value) {
RemoveKey(key); RemoveKey(key);
@ -152,7 +172,7 @@ class TSimpleStringDictionary {
return; return;
} }
// Key must not be an empty string. // |key| must not be an empty string.
DCHECK_NE(key[0], '\0'); DCHECK_NE(key[0], '\0');
if (key[0] == '\0') { if (key[0] == '\0') {
return; return;
@ -194,8 +214,11 @@ class TSimpleStringDictionary {
entry->value[value_size - 1] = '\0'; entry->value[value_size - 1] = '\0';
} }
// Given |key|, removes any associated value. |key| must not be NULL. If the //! \brief Removes \a key from the map.
// key is not found, this is a noop. //!
//! If the key is not found, this is a no-op.
//!
//! \param[in] key The key of the entry to remove. This must not be `NULL`.
void RemoveKey(const char* key) { void RemoveKey(const char* key) {
DCHECK(key); DCHECK(key);
if (!key) { if (!key) {
@ -211,10 +234,13 @@ class TSimpleStringDictionary {
DCHECK_EQ(GetEntryForKey(key), static_cast<void*>(NULL)); DCHECK_EQ(GetEntryForKey(key), static_cast<void*>(NULL));
} }
// Places a serialized version of the map into |map| and returns the size. //! \brief Returns a serialized form of the map.
// Both of these should be passed to the deserializing constructor. Note that //!
// the serialized |map| is scoped to the lifetime of the non-serialized //! Places a serialized version of the map into \a map and returns the size in
// instance of this class. The |map| can be copied across IPC boundaries. //! bytes. Both \a map and the size should be passed to the deserializing
//! constructor. Note that the serialized \a map is scoped to the lifetime of
//! the non-serialized instance of this class. The \a map data can be copied
//! across IPC boundaries.
size_t Serialize(const SerializedSimpleStringDictionary** map) const { size_t Serialize(const SerializedSimpleStringDictionary** map) const {
*map = reinterpret_cast<const SerializedSimpleStringDictionary*>(entries_); *map = reinterpret_cast<const SerializedSimpleStringDictionary*>(entries_);
return sizeof(entries_); return sizeof(entries_);
@ -237,8 +263,10 @@ class TSimpleStringDictionary {
Entry entries_[NumEntries]; Entry entries_[NumEntries];
}; };
// For historical reasons this specialized version is available with the same //! \brief A TSimpleStringDictionary with default template parameters.
// size factors as a previous implementation. //!
//! For historical reasons this specialized version is available with the same
//! size factors as a previous implementation.
typedef TSimpleStringDictionary<256, 256, 64> SimpleStringDictionary; typedef TSimpleStringDictionary<256, 256, 64> SimpleStringDictionary;
} // namespace crashpad } // namespace crashpad