📄 nameinfo.hh
字号:
virtual ~NameDB() { NameInfo::uninstalldb(this); } /** @brief Return the database type. */ uint32_t type() const { return _type; } /** @brief Return the database's compound element context as a string. */ const String &context() const { return _context; } /** @brief Return the contextual parent database, if any. * * The contextual parent database is the unique database, for the same * router, with the same type(), whose context() is a prefix of this * database's context(), that has the longest context() of any matching * database. If there is no such database returns null. */ NameDB *context_parent() const { return _context_parent; } /** @brief Return the database's value size. */ size_t value_size() const { return _value_size; } /** @brief Query this database for a given name. * @param name name to look up * @param value points to value storage * @param value_size size of value storage * @return true iff the query succeeded * * The @a value_size parameter must equal this database's value size. */ virtual bool query(const String &name, void *value, size_t value_size) = 0; /** @brief Query this database for a given value. * @param value points to value to look up * @param value_size size of value storage * @return the name for the given value, or an empty string if the value * has not been defined * * The @a value_size parameter must equal this database's value size. * The default implementation always returns the empty string. */ virtual String revquery(const void *value, size_t value_size); /** @brief Define a name in this database to a given value. * @param name name to define * @param value points to value to define * @param value_size size of value storage * @return true iff the name was defined * * The @a value_size parameter must equal this database's value size. * The default implementation always returns false. */ virtual bool define(const String &name, const void *value, size_t value_size); /** @brief Define a name in this database to a 32-bit integer value. * @param name name to define * @param value value to define * @return true iff the name was defined * * The database's value size must equal 4. The implementation is the same * as <code>define(name, &value, 4)</code>. */ inline bool define_int(const String &name, int32_t value);#if CLICK_NAMEDB_CHECK /** @cond never */ virtual void check(ErrorHandler *); /** @endcond never */#endif private: uint32_t _type; String _context; size_t _value_size; NameDB *_context_parent; NameDB *_context_sibling; NameDB *_context_child; NameInfo *_installed;#if CLICK_NAMEDB_CHECK uintptr_t _check_generation;#endif friend class NameInfo;};class StaticNameDB : public NameDB { public: struct Entry { const char *name; uint32_t value; }; /** @brief Construct a static name database. * @param type database type * @param context database compound element context, as a String * @param entry pointer to static entry list * @param nentry number of entries * * The entry array specifies the contents of the database. It must be * sorted by name: entry[i].name < entry[i+1].name for all 0 <= i < * nentry-1. The entry array must also persist as long as the database is * in use; the database doesn't copy the entry array into its own memory, * but continues to use the array passed in. The resulting database has * value_size() 4. */ inline StaticNameDB(uint32_t type, const String &context, const Entry *entry, size_t nentry); /** @brief Query this database for a given name. * @param name name to look up * @param value points to value storage * @param value_size size of value storage * @return true iff the query succeeded * * The @a value_size parameter must equal 4. */ bool query(const String &name, void *value, size_t value_size); /** @brief Query this database for a given value. * @param value points to value to look up * @param value_size size of value storage * @return the name for the given value, or an empty string if the value * has not been defined * * The @a value_size parameter must equal 4. */ String revquery(const void *value, size_t value_size);#if CLICK_NAMEDB_CHECK /** @cond never */ void check(ErrorHandler *); /** @endcond never */#endif private: const Entry *_entries; size_t _nentries;};class DynamicNameDB : public NameDB { public: /** @brief Construct a dynamic name database. * @param type database type * @param context database compound element context, as a String * @param value_size database value size * * @a value_size must be greater than 0. The database is initially * empty. */ inline DynamicNameDB(uint32_t type, const String &context, size_t value_size); /** @brief Query this database for a given name. * @param name name to look up * @param value points to value storage * @param value_size size of value storage * @return true iff the query succeeded * * The @a value_size parameter must equal this database's value size. */ bool query(const String &name, void *value, size_t value_size); /** @brief Query this database for a given value. * @param value points to value to look up * @param value_size size of value storage * @return the name for the given value, or an empty string if the value * has not been defined * * The @a value_size parameter must equal this database's value size. */ String revquery(const void *value, size_t value_size); /** @brief Define a name in this database to a given value. * @param name name to define * @param value points to value to define * @param value_size size of value storage * @return true iff the name was defined * * The @a value_size parameter must equal this database's value size. */ bool define(const String &name, const void *value, size_t value_size);#if CLICK_NAMEDB_CHECK /** @cond never */ void check(ErrorHandler *); /** @endcond never */#endif private: Vector<String> _names; StringAccum _values; int _sorted; void *find(const String &name, bool create); void sort();};inlineNameDB::NameDB(uint32_t type, const String &context, size_t vsize) : _type(type), _context(context), _value_size(vsize), _context_parent(0), _context_sibling(0), _context_child(0), _installed(0){#if CLICK_NAMEDB_CHECK _check_generation = 0;#endif assert(_value_size > 0);}inlineStaticNameDB::StaticNameDB(uint32_t type, const String &context, const Entry *entry, size_t nentry) : NameDB(type, context, sizeof(entry->value)), _entries(entry), _nentries(nentry){}inlineDynamicNameDB::DynamicNameDB(uint32_t type, const String &context, size_t vsize) : NameDB(type, context, vsize), _sorted(0){}inline StringNameInfo::revquery_int(uint32_t type, const Element *e, int32_t value){ return revquery(type, e, &value, sizeof(value));}inline boolNameInfo::define(uint32_t type, const Element *e, const String &name, const void *value, size_t vsize){ if (NameDB *db = getdb(type, e, vsize, true)) return db->define(name, value, vsize); else return false;}inline boolNameInfo::define_int(uint32_t type, const Element *e, const String &name, const int32_t value){ if (NameDB *db = getdb(type, e, sizeof(value), true)) return db->define(name, &value, sizeof(value)); else return false;}inline boolNameDB::define_int(const String &name, const int32_t value){ return define(name, &value, sizeof(value));}CLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -