From: Marcin Siodelski Date: Thu, 14 Feb 2013 13:38:03 +0000 (+0100) Subject: [2701] Added the key_from_key.h header file. X-Git-Tag: bind10-1.1.0beta1-release~60^2^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b58a4e5e12ee86e6ece24e90bc2f1e854cd92527;p=thirdparty%2Fkea.git [2701] Added the key_from_key.h header file. --- diff --git a/src/lib/dhcpsrv/key_from_key.h b/src/lib/dhcpsrv/key_from_key.h new file mode 100644 index 0000000000..9dcbc3bb5a --- /dev/null +++ b/src/lib/dhcpsrv/key_from_key.h @@ -0,0 +1,69 @@ +// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef KEY_FROM_KEY_H +#define KEY_FROM_KEY_H + +#include + +namespace isc { +namespace dhcp { + +/// @brief Extractor class to extract key with another key. +/// +/// This class solves the problem whereby the multi_index_container +/// must access the values stored in object nested in other object. +/// Assume that there is a multi_index_container that holds objects +/// of the type A. Each object A contains the member object B. +/// Each object B holds the member of the type C that is to be used +/// for indexing objects A. Objects C can't be accessed directly +/// from the object A as they are nested in the object B. In such case +/// there is no easy way to point in the definition of the container +/// that C should be used for indexing objects. The KeyFromKey class +/// represents the cascaded key which can be used to extract the nested +/// key value C from the object B. +/// For some more examples of complex keys see: +/// http://www.cs.brown.edu/~jwicks/boost/libs/multi_index/doc/index.html +/// +/// @tparam KeyExtractor1 extractor used to access the object used as +/// a key from the other object that holds it. +/// @tparam KeyExtractor2 extractor used to access data in the object +/// holding nested object used as a key. +template +class KeyFromKey { +public: + typedef typename KeyExtractor1::result_type result_type; + + /// @brief Constructor. + KeyFromKey() + : key1_(KeyExtractor1()), key2_(KeyExtractor2()) { }; + + /// @brief Extract key with another key. + /// + /// @param arg the key value. + /// + /// @tparam key value type. + template + result_type operator() (T& arg) const { + return (key1_(key2_(arg))); + } +private: + KeyExtractor1 key1_; ///< key 1. + KeyExtractor2 key2_; ///< key 2. +}; + +} // end of isc::dhcp namespace +} // end of isc namespace + +#endif // KEY_FROM_KEY_H