src/config/config.cc
/*
 * Attempts to get the value assigned to the given key in the configuration
 * dictionary. If the key is not in the dictionary, the given default value
 * is assigned set and returned. If no default is given, NULL is returned
 * and no value is set.
 *
 * Assumes the given key is non-null and non-empty.
 *
 * The returned value must not be deleted.
 */
Attempts to get the value assigned to the given key in the configuration
dictionary. If the key is not in the dictionary, the given default value
is assigned set and returned. If no default is given, NULL is returned
and no value is set.

Assumes the given key is non-null and non-empty.

The returned value must not be deleted.
Attempts to get the value assigned to the given key in the configuration dictionary . If the key is not in the dictionary the given default value is assigned set and returned . If no default is given NULL is returned and no value is set . Assumes the given key is non - null and non - empty . The returned value must not be deleted .
const char *Config::Get(const char *key, const char *default_value) {
  size_t index = Hash(key);
  DictElem *elem = dict_[index];
  DictElem *last_elem = NULL;
  while (elem != NULL) {
    if (StrEq(elem->key, key)) { return elem->val; }
    last_elem = elem;
    elem = elem->next;
  }
  if (default_value != NULL) {
    if (last_elem == NULL) {
      dict_[index] = new DictElem();
      elem = dict_[index];
    } else {
      last_elem->next = new DictElem();
      elem = last_elem->next;
    }
    elem->key = StrCpy(key);
    elem->val = StrCpy(default_value);
    return elem->val;
  }
  return NULL;
}
const char * Config :: Get ( const char * key , const char * default_value ) { size_t index = Hash ( key ) ; DictElem * elem = dict_ [ index ] ; DictElem * last_elem = NULL ; while ( elem != NULL ) { if ( StrEq ( elem -> key , key ) ) { return elem -> val ; } last_elem = elem ; elem = elem -> next ; } if ( default_value != NULL ) { if ( last_elem == NULL ) { dict_ [ index ] = new DictElem ( ) ; elem = dict_ [ index ] ; } else { last_elem -> next = new DictElem ( ) ; elem = last_elem -> next ; } elem -> key = StrCpy ( key ) ; elem -> val = StrCpy ( default_value ) ; return elem -> val ; } return NULL ; }
Attempts to get the value assigned to the given key in the configuration
 dictionary.
Attempts to get the value assigned to the given key in the configuration dictionary .
// Get the index of the key, and check if it's in the list. // If the key was not in the dictionary, and a default was provided, // the default is added to the list and then returned. // Checks if this element is the start of a new list. // Otherwise, the element is added to the end of the list. // Creates copies of the key and value for the element, then returns // the value. // Otherwise, NULL is returned as no value could be found.