From 953805d97e7f0bc5e39a7570cc02a82b02aee752 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 20 Mar 2014 08:23:44 -0700 Subject: [PATCH] Add const_container --- .../Builds/VisualStudio2013/beast.vcxproj | 1 + .../VisualStudio2013/beast.vcxproj.filters | 3 + src/beast/beast/container/const_container.h | 99 +++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/beast/beast/container/const_container.h diff --git a/src/beast/Builds/VisualStudio2013/beast.vcxproj b/src/beast/Builds/VisualStudio2013/beast.vcxproj index 2b10a2033..3e65afc79 100644 --- a/src/beast/Builds/VisualStudio2013/beast.vcxproj +++ b/src/beast/Builds/VisualStudio2013/beast.vcxproj @@ -127,6 +127,7 @@ + diff --git a/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters b/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters index 952d4caf8..1282af939 100644 --- a/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters +++ b/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters @@ -1161,6 +1161,9 @@ beast\utility + + beast\container + diff --git a/src/beast/beast/container/const_container.h b/src/beast/beast/container/const_container.h new file mode 100644 index 000000000..43d02c490 --- /dev/null +++ b/src/beast/beast/container/const_container.h @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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 THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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 BEAST_CONTAINER_CONST_CONTAINER_H_INCLUDED +#define BEAST_CONTAINER_CONST_CONTAINER_H_INCLUDED + +namespace beast { + +/** Adapter to constrain a container interface. + The interface allows for limited read only operations. Derived classes + provide additional behavior. +*/ +template +class const_container +{ +private: + typedef Container cont_type; + + cont_type m_cont; + +protected: + cont_type& cont() + { + return m_cont; + } + + cont_type const& cont() const + { + return m_cont; + } + +public: + typedef typename cont_type::value_type value_type; + typedef typename cont_type::size_type size_type; + typedef typename cont_type::difference_type difference_type; + typedef typename cont_type::const_iterator iterator; + typedef typename cont_type::const_iterator const_iterator; + + /** Returns `true` if the container is empty. */ + bool + empty() const + { + return m_cont.empty(); + } + + /** Returns the number of items in the container. */ + size_type + size() const + { + return m_cont.size(); + } + + /** Returns forward iterators for traversal. */ + /** @{ */ + const_iterator + begin() const + { + return m_cont.cbegin(); + } + + const_iterator + cbegin() const + { + return m_cont.cbegin(); + } + + const_iterator + end() const + { + return m_cont.cend(); + } + + const_iterator + cend() const + { + return m_cont.cend(); + } + /** @} */ +}; + +} // beast + +#endif