From e59cccfceb9d411cc87988fdd041a7a71851ebcc Mon Sep 17 00:00:00 2001 From: lucapegolotti Date: Fri, 29 Apr 2016 15:01:21 +0200 Subject: [PATCH] containers_cpp: improve style uniformity and readability --- containers_cpp/include/embb/containers/blocking_map.h | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- containers_cpp/include/embb/containers/blocking_priority_queue.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- containers_cpp/include/embb/containers/blocking_queue.h | 77 +++++++++++++++++++++++++++++++++++++++++++++-------------------------------- containers_cpp/include/embb/containers/blocking_set.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- containers_cpp/include/embb/containers/blocking_stack.h | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------ containers_cpp/include/embb/containers/internal/blocking_map-inl.h | 51 ++++++++++++++++++++++++--------------------------- containers_cpp/include/embb/containers/internal/blocking_priority_queue-inl.h | 50 ++++++++++++++++++++++++-------------------------- containers_cpp/include/embb/containers/internal/blocking_push_and_pop_container.h | 52 ++++++++++++++++++++++++++-------------------------- containers_cpp/include/embb/containers/internal/blocking_queue-inl.h | 3 +-- containers_cpp/include/embb/containers/internal/blocking_set-inl.h | 91 +++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------- containers_cpp/include/embb/containers/internal/blocking_stack-inl.h | 4 +--- 11 files changed, 438 insertions(+), 330 deletions(-) diff --git a/containers_cpp/include/embb/containers/blocking_map.h b/containers_cpp/include/embb/containers/blocking_map.h index 3d857fa..4f6ed95 100755 --- a/containers_cpp/include/embb/containers/blocking_map.h +++ b/containers_cpp/include/embb/containers/blocking_map.h @@ -1,28 +1,28 @@ /* -* Copyright (c) 2014-2016, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_BLOCKING_MAP_H_ #define EMBB_CONTAINERS_BLOCKING_MAP_H_ @@ -33,26 +33,77 @@ namespace embb { namespace containers { +/** + * Blocking map. + * + * \tparam Key Key type of the elements in the map. + * \tparam Value Value type of the elements in the map. + */ template< typename Key, typename Value> class BlockingMap { typedef embb::base::Mutex Mutex; typedef embb::base::LockGuard<> LockGuard; private: + /** + * Internal map from the standard library. + */ std::map internalMap; + /** + * Mutex for synchronizing concurrent accesses to the structure. + */ Mutex mutex; public: + /** + * Creates an empty map. + */ BlockingMap(); - bool Insert(const Key& key, const Value& value); - - bool Erase(const Key& key); - - bool Contains(const Key& key); - - Value& operator[](const Key& key); + /** + * Inserts a new element (key,value) in the map, if no elements + * with the same key already exists. + * + * \return \c true if the inserting succeeded, + * \c false otherwise. + */ + bool Insert( + const Key& key, + /**< [IN] Constant reference to key of the element to insert*/ + const Value& value + /**< [IN] Constant reference to value of the element to insert*/ + ); + + /** + * Erases the element with the specified key, if such an element exists. + * + * \return \c true if erasing was successfull, \c false otherwise. + */ + bool Erase( + const Key& key + /**< [IN] Constant reference to the key of the element to erase*/); + + /* + * Checks if the map contains an element with the specified key. + * + * \return \c true if the the map contains the element, \c false + * otherwise + */ + bool Contains( + const Key& key + /**< [IN] Constant reference to key of the element + to search for*/); + + /** + * Accesses the element with the specified key, if such an element exists. + * If it does not exists, creates an element with the specified key. + * + * \return Reference to the value with the specified key. + */ + Value& operator[]( + const Key& key + /**< [IN] Constant reference to key of the element to access*/); }; @@ -61,5 +112,5 @@ class BlockingMap { #include -#endif EMBB_CONTAINERS_BLOCKING_MAP_H_ +#endif // EMBB_CONTAINERS_BLOCKING_MAP_H_ diff --git a/containers_cpp/include/embb/containers/blocking_priority_queue.h b/containers_cpp/include/embb/containers/blocking_priority_queue.h index 0a94122..a6f1a95 100755 --- a/containers_cpp/include/embb/containers/blocking_priority_queue.h +++ b/containers_cpp/include/embb/containers/blocking_priority_queue.h @@ -1,54 +1,84 @@ /* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE_H_ #define EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE_H_ #include - #include namespace embb { namespace containers { /** -* Wrapper for the standard library priority_queue. -* -* \tparam T Element type -*/ + * Blocking priority queue. + * + * \concept{CPP_CONCEPTS_QUEUE} + * + * \ingroup CPP_CONTAINERS_QUEUES + * + * \see WaitFreeSPSCQueue, LockFreeMPMCQueue, BlockingQueue + * + * \tparam Type Element type + * \tparam Container Type of the underlying container + * \tparam Compare Type of the ordering of the container, + * which determines what element will be + * dequeued next. + */ template< typename Type, class Container = std::vector, class Compare = std::less> class BlockingPriorityQueue : public BlockingPushAndPopContainer { - private: /** * Internal priority_queue from the standard library. */ std::priority_queue internalQueue; + + /** + * Wrapper for the push method in the standard priority_queue. + * Implements the corresponding pure virtual method + * in the super class. + */ + void SpecializedPush(const Type& element); + + /** + * Wrapper for the pop method in the standard priority_queue. + * Implements the corresponding pure virtual method + * in the super class. + */ + void SpecializedPop(Type& element); + + /** + * Wrapper for the empty method in the standard priority_queue. + * Implements the corresponding pure virtual method + * in the super class. + */ + bool IsEmpty(); + public: /** * Enqueues an element in the internal priority_queue. @@ -60,27 +90,6 @@ class BlockingPriorityQueue : public BlockingPushAndPopContainer { void Dequeue( Type& element /**< [IN] Reference to dequeued element*/); - - protected: - /* - * Wrapper for the push method in the standard priority_queue. - */ - virtual void SpecializedPush( - const Type& element - /**< [IN] Constant reference to element to push.*/); - - /** - * Wrapper for the pop method in the standard priority_queue. - */ - virtual void SpecializedPop( - Type& element - /**< [IN,OUT] Reference to element to the popped element*/); - - /** - * Wrapper for the empty method in the standard priority_queue. - */ - virtual bool IsEmpty(); - }; } // namespace containers diff --git a/containers_cpp/include/embb/containers/blocking_queue.h b/containers_cpp/include/embb/containers/blocking_queue.h index 060ec0f..6beb436 100755 --- a/containers_cpp/include/embb/containers/blocking_queue.h +++ b/containers_cpp/include/embb/containers/blocking_queue.h @@ -1,5 +1,5 @@ - /* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. +/* + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -28,55 +28,68 @@ #define EMBB_CONTAINERS_BLOCKING_QUEUE_H_ #include - #include namespace embb { namespace containers { /** -* Wrapper for the standard library queue. -* -* \tparam T Element type -*/ + * Blocking queue. + * + * \concept{CPP_CONCEPTS_QUEUE} + * + * \ingroup CPP_CONTAINERS_QUEUES + * + * \see WaitFreeSPSCQueue, LockFreeMPMCQueue, BlockingPriorityQueue + * + * \tparam Type Element type + */ template< typename Type> class BlockingQueue : public BlockingPushAndPopContainer { private: /** - * Internal queue from the standard library. - */ + * Internal queue from the standard library. + */ std::queue internalQueue; - public: + /** - * Enqueues an element in the internal queue. - */ - void Enqueue( - const Type& element - /**< [IN] Constant reference to element to enqueue*/); + * Wrapper for push_back method in the standard library queue. + * Implements the corresponding pure virtual method + * in the super class. + */ + void SpecializedPush(const Type& element); + + /** + * Wrapper for pop_front method in the standard library queue. + * Implements the corresponding pure virtual method + * in the super class. + */ + void SpecializedPop(Type& element); - void Dequeue( - Type& element - /**< [IN] Reference to dequeued element*/); + /** + * Wrapper for the empty method in the standard queue. + * Implements the corresponding pure virtual method + * in the super class. + */ + bool IsEmpty(); - protected: - /* - * Wrapper for the push method in the standard queue. + public: + /** + * Enqueues an element in the priority queue. */ - virtual void SpecializedPush( + void Enqueue( const Type& element - /**< [IN] Constant reference to element to push.*/); + /**< [IN] Constant reference to element to enqueue*/); /** - * Wrapper for the pop method in the standard queue. - */ - virtual void SpecializedPop( + * Dequeues the next element from the priority queue. + * What element will be dequeued is determined by the Compare + * template parameter. By default, the next returned element is + * the one with the largest key. + */ + void Dequeue( Type& element - /**< [IN,OUT] Reference to element to the popped element*/); - - /** - * Wrapper for the empty method in the standard queue. - */ - virtual bool IsEmpty(); + /**< [IN, OUT] Reference to dequeued element*/); }; diff --git a/containers_cpp/include/embb/containers/blocking_set.h b/containers_cpp/include/embb/containers/blocking_set.h index 495c650..cdf8c5e 100755 --- a/containers_cpp/include/embb/containers/blocking_set.h +++ b/containers_cpp/include/embb/containers/blocking_set.h @@ -1,28 +1,28 @@ /* -* Copyright (c) 2014-2015, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_BLOCKING_SET_H_ #define EMBB_CONTAINERS_BLOCKING_SET_H_ @@ -36,27 +36,62 @@ namespace embb { namespace containers { /* -* Wrapper for the standard library set. -* -* \tparam T Element type. -*/ + * Blocking set. + * + * \tparam Type Element type. + */ template < typename Type > class BlockingSet { typedef embb::base::Mutex Mutex; typedef embb::base::LockGuard LockGuard; + private: + /** + * Internal set from the standard library + */ std::set internalSet; + /** + * Mutex for synchronizing the accesses + * to the structure. + */ Mutex mutex; public: + /** + * Creates an empty set. + */ BlockingSet(); - bool Insert(const Type& element); + /** + * Inserts an element in the set. + * + * \return \c true if the element has been inserted (i.e. + * it was not already in the set), \c false otherwise. + */ + bool Insert( + const Type& element + /**< [IN] Reference to the element to insert. */); - bool Erase(const Type& element); + /** + * Erases an element from the set. + * + * \return \c true if the element has been erased (which means + * that it was in the set) \c false otherwise. + */ + bool Erase( + const Type& element + /**< [IN] Reference to the element to erase. */); - bool Contains(const Type& element); + /** + * Checks if the an element is in the set. + * + * \return \c true if the element is in the set, + * \c false otherwise. + */ + bool Contains( + const Type& element + /**< [IN] Reference to the element to search for. */); }; diff --git a/containers_cpp/include/embb/containers/blocking_stack.h b/containers_cpp/include/embb/containers/blocking_stack.h index aa0c44b..c644cd4 100755 --- a/containers_cpp/include/embb/containers/blocking_stack.h +++ b/containers_cpp/include/embb/containers/blocking_stack.h @@ -1,82 +1,91 @@ /* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_BLOCKING_STACK_H_ #define EMBB_CONTAINERS_BLOCKING_STACK_H_ #include - #include namespace embb { namespace containers { /** -* Wrapper for the standard library stack. -* -* \tparam T Element type -*/ + * Blocking stack. + * + * \concept{CPP_CONCEPTS_STACK} + * + * \ingroup CPP_CONTAINERS_STACKS + * + * \tparam Type Type of the stack elements + * + */ template< typename Type> class BlockingStack : public BlockingPushAndPopContainer { private: /** - * Internal stack from the standard library. - */ + * Internal stack from the standard library. + */ std::stack internalStack; - public: + + /* + * Wrapper for the push method in the standard stack. + * Implements the corresponding pure virtual method + * in the super class. + */ + void SpecializedPush(const Type& element); + /** - * Enstacks an element in the internal stack. - */ - void Push( - const Type& element - /**< [IN] Constant reference to element to push*/); + * Wrapper for the pop method in the standard stack. + * Implements the corresponding pure virtual method + * in the super class. + */ + void SpecializedPop(Type& element); - void Pop( - Type& element - /**< [IN] Reference to popped element*/); + /** + * Wrapper for the empty method in the standard stack. + * Implements the corresponding pure virtual method + * in the super class + */ + bool IsEmpty(); - protected: - /* - * Wrapper for the push method in the standard stack. + public: + /** + * Pushes an element in the stack. */ - virtual void SpecializedPush( + void Push( const Type& element - /**< [IN] Constant reference to element to push.*/); + /**< [IN] Constant reference to element to push*/); /** - * Wrapper for the pop method in the standard stack. - */ - virtual void SpecializedPop( + * Pop an element from the stack. + */ + void Pop( Type& element - /**< [IN,OUT] Reference to element to the popped element*/); - - /** - * Wrapper for the empty method in the standard stack. - */ - virtual bool IsEmpty(); + /**< [IN, OUT] Reference to popped element*/); }; diff --git a/containers_cpp/include/embb/containers/internal/blocking_map-inl.h b/containers_cpp/include/embb/containers/internal/blocking_map-inl.h index 84e2ebb..b64d4b9 100755 --- a/containers_cpp/include/embb/containers/internal/blocking_map-inl.h +++ b/containers_cpp/include/embb/containers/internal/blocking_map-inl.h @@ -1,33 +1,32 @@ /* -* Copyright (c) 2014-2016, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_INTERNAL_BLOCKING_MAP_INL_H_ #define EMBB_CONTAINERS_INTERNAL_BLOCKING_SET_INL_H_ - namespace embb { namespace containers { @@ -35,7 +34,6 @@ template BlockingMap::BlockingMap() : internalMap() {} - template bool BlockingMap::Insert(const K& key, const V& value) { LockGuard lock(mutex); @@ -60,7 +58,6 @@ V& BlockingMap::operator[](const K& key) { return internalMap[key]; } - } } diff --git a/containers_cpp/include/embb/containers/internal/blocking_priority_queue-inl.h b/containers_cpp/include/embb/containers/internal/blocking_priority_queue-inl.h index e704eef..7f4d682 100755 --- a/containers_cpp/include/embb/containers/internal/blocking_priority_queue-inl.h +++ b/containers_cpp/include/embb/containers/internal/blocking_priority_queue-inl.h @@ -1,28 +1,28 @@ /* -* Copyright (c) 2014-2015, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_INTERNAL_BLOCKING_PRIORITY_QUEUE_INL_H_ #define EMBB_CONTAINERS_INTERNAL_BLOCKING_PRIORITY_QUEUE_INL_H_ @@ -56,9 +56,7 @@ bool BlockingPriorityQueue::IsEmpty() { return internalQueue.empty(); } - } } - #endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_PRIORITY_QUEUE_INL_H_ \ No newline at end of file diff --git a/containers_cpp/include/embb/containers/internal/blocking_push_and_pop_container.h b/containers_cpp/include/embb/containers/internal/blocking_push_and_pop_container.h index b90b07e..ab9c6da 100755 --- a/containers_cpp/include/embb/containers/internal/blocking_push_and_pop_container.h +++ b/containers_cpp/include/embb/containers/internal/blocking_push_and_pop_container.h @@ -1,28 +1,28 @@ /* -* Copyright (c) 2014-2015, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_BLOCKING_PUSH_AND_POP_CONTAINER_H_ #define EMBB_CONTAINERS_BLOCKING_PUSH_AND_POP_CONTAINER_H_ @@ -30,10 +30,11 @@ #include - namespace embb { namespace containers { +// Abstract class, provides a synchronization mechanism for +// data structures that support push/pop-like methods (e.g. stacks, queues) template < typename Type > class BlockingPushAndPopContainer { @@ -69,7 +70,6 @@ class BlockingPushAndPopContainer { SpecializedPop(element); } - }; } diff --git a/containers_cpp/include/embb/containers/internal/blocking_queue-inl.h b/containers_cpp/include/embb/containers/internal/blocking_queue-inl.h index fb627c4..f48c1c8 100755 --- a/containers_cpp/include/embb/containers/internal/blocking_queue-inl.h +++ b/containers_cpp/include/embb/containers/internal/blocking_queue-inl.h @@ -1,6 +1,5 @@ -#include "..\blocking_queue.h" /* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/containers_cpp/include/embb/containers/internal/blocking_set-inl.h b/containers_cpp/include/embb/containers/internal/blocking_set-inl.h index eae2296..aa8843a 100755 --- a/containers_cpp/include/embb/containers/internal/blocking_set-inl.h +++ b/containers_cpp/include/embb/containers/internal/blocking_set-inl.h @@ -1,57 +1,56 @@ /* -* Copyright (c) 2014-2015, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef EMBB_CONTAINERS_INTERNAL_BLOCKING_SET_INL_H_ #define EMBB_CONTAINERS_INTERNAL_BLOCKING_SET_INL_H_ - namespace embb { namespace containers { - template - BlockingSet::BlockingSet() : - internalSet() {} - - template - bool BlockingSet::Insert(const T& element){ - LockGuard lock(mutex); - return internalSet.insert(element).second; - } - - template - bool BlockingSet::Erase(const T& element){ - LockGuard lock(mutex); - return internalSet.erase(element) > 0; - } - - template - bool BlockingSet::Contains(const T& element){ - LockGuard lock(mutex); - return internalSet.find(element) != internalSet.end(); - } +template +BlockingSet::BlockingSet() : + internalSet() {} + +template +bool BlockingSet::Insert(const T& element){ + LockGuard lock(mutex); + return internalSet.insert(element).second; +} + +template +bool BlockingSet::Erase(const T& element){ + LockGuard lock(mutex); + return internalSet.erase(element) > 0; +} + +template +bool BlockingSet::Contains(const T& element){ + LockGuard lock(mutex); + return internalSet.find(element) != internalSet.end(); +} } } diff --git a/containers_cpp/include/embb/containers/internal/blocking_stack-inl.h b/containers_cpp/include/embb/containers/internal/blocking_stack-inl.h index 8e69445..8a24a24 100755 --- a/containers_cpp/include/embb/containers/internal/blocking_stack-inl.h +++ b/containers_cpp/include/embb/containers/internal/blocking_stack-inl.h @@ -1,6 +1,5 @@ -#include "..\blocking_stack.h" /* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -28,7 +27,6 @@ #ifndef EMBB_CONTAINERS_INTERNAL_BLOCKING_STACK_INL_H_ #define EMBB_CONTAINERS_INTERNAL_BLOCKING_STACK_INL_H_ - namespace embb { namespace containers { -- libgit2 0.26.0