Commit db171626 by lucapegolotti

containers_cpp: fix cpplint warnings

parent e59cccfc
...@@ -45,72 +45,71 @@ class BlockingMap { ...@@ -45,72 +45,71 @@ class BlockingMap {
typedef embb::base::LockGuard<> LockGuard; typedef embb::base::LockGuard<> LockGuard;
private: private:
/** /**
* Internal map from the standard library. * Internal map from the standard library.
*/ */
std::map<Key, Value> internalMap; std::map<Key, Value> internalMap;
/** /**
* Mutex for synchronizing concurrent accesses to the structure. * Mutex for synchronizing concurrent accesses to the structure.
*/ */
Mutex mutex; Mutex mutex;
public: public:
/** /**
* Creates an empty map. * Creates an empty map.
*/ */
BlockingMap(); BlockingMap();
/** /**
* Inserts a new element (key,value) in the map, if no elements * Inserts a new element (key,value) in the map, if no elements
* with the same key already exists. * with the same key already exists.
* *
* \return \c true if the inserting succeeded, * \return \c true if the inserting succeeded,
* \c false otherwise. * \c false otherwise.
*/ */
bool Insert( bool Insert(
const Key& key, const Key& key,
/**< [IN] Constant reference to key of the element to insert*/ /**< [IN] Constant reference to key of the element to insert*/
const Value& value const Value& value
/**< [IN] Constant reference to value of the element to insert*/ /**< [IN] Constant reference to value of the element to insert*/
); );
/** /**
* Erases the element with the specified key, if such an element exists. * Erases the element with the specified key, if such an element exists.
* *
* \return \c true if erasing was successfull, \c false otherwise. * \return \c true if erasing was successfull, \c false otherwise.
*/ */
bool Erase( bool Erase(
const Key& key const Key& key
/**< [IN] Constant reference to the key of the element to erase*/); /**< [IN] Constant reference to the key of the element to erase*/);
/* /*
* Checks if the map contains an element with the specified key. * Checks if the map contains an element with the specified key.
* *
* \return \c true if the the map contains the element, \c false * \return \c true if the the map contains the element, \c false
* otherwise * otherwise
*/ */
bool Contains( bool Contains(
const Key& key const Key& key
/**< [IN] Constant reference to key of the element /**< [IN] Constant reference to key of the element
to search for*/); to search for*/);
/** /**
* Accesses the element with the specified key, if such an element exists. * Accesses the element with the specified key, if such an element exists.
* If it does not exists, creates an element with the specified key. * If it does not exists, creates an element with the specified key.
* *
* \return Reference to the value with the specified key. * \return Reference to the value with the specified key.
*/ */
Value& operator[]( Value& operator[](
const Key& key const Key& key
/**< [IN] Constant reference to key of the element to access*/); /**< [IN] Constant reference to key of the element to access*/);
}; };
} } // namespace containers
} } // namespace embb
#include <embb/containers/internal/blocking_map-inl.h> #include <embb/containers/internal/blocking_map-inl.h>
#endif // EMBB_CONTAINERS_BLOCKING_MAP_H_ #endif // EMBB_CONTAINERS_BLOCKING_MAP_H_
...@@ -23,16 +23,18 @@ ...@@ -23,16 +23,18 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE_H_ #ifndef EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE_H_
#define EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE_H_ #define EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE_H_
#include <queue>
#include <embb/containers/internal/blocking_push_and_pop_container.h> #include <embb/containers/internal/blocking_push_and_pop_container.h>
#include <functional>
#include <vector>
#include <queue>
namespace embb { namespace embb {
namespace containers { namespace containers {
/** /**
* Blocking priority queue. * Blocking priority queue.
* *
...@@ -48,15 +50,15 @@ namespace containers { ...@@ -48,15 +50,15 @@ namespace containers {
* which determines what element will be * which determines what element will be
* dequeued next. * dequeued next.
*/ */
template< typename Type, template< typename Type,
class Container = std::vector<Type>, class Container = std::vector<Type>,
class Compare = std::less<typename Container::value_type>> class Compare = std::less<typename Container::value_type>>
class BlockingPriorityQueue : public BlockingPushAndPopContainer<Type> { class BlockingPriorityQueue : public BlockingPushAndPopContainer<Type> {
private: private:
/** /**
* Internal priority_queue from the standard library. * Internal priority_queue from the standard library.
*/ */
std::priority_queue<Type, Container,Compare> internalQueue; std::priority_queue<Type, Container, Compare> internalQueue;
/** /**
* Wrapper for the push method in the standard priority_queue. * Wrapper for the push method in the standard priority_queue.
...@@ -86,15 +88,15 @@ class BlockingPriorityQueue : public BlockingPushAndPopContainer<Type> { ...@@ -86,15 +88,15 @@ class BlockingPriorityQueue : public BlockingPushAndPopContainer<Type> {
void Enqueue( void Enqueue(
const Type& element const Type& element
/**< [IN] Constant reference to element to enqueue*/); /**< [IN] Constant reference to element to enqueue*/);
void Dequeue( void Dequeue(
Type& element Type& element
/**< [IN] Reference to dequeued element*/); /**< [IN] Reference to dequeued element*/);
}; };
} // namespace containers } // namespace containers
} // namespace embb } // namespace embb
#include <embb/containers/internal/blocking_priority_queue-inl.h> #include <embb/containers/internal/blocking_priority_queue-inl.h>
#endif // EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE #endif // EMBB_CONTAINERS_BLOCKING_PRIORITY_QUEUE_H_
\ No newline at end of file
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
#ifndef EMBB_CONTAINERS_BLOCKING_QUEUE_H_ #ifndef EMBB_CONTAINERS_BLOCKING_QUEUE_H_
#define EMBB_CONTAINERS_BLOCKING_QUEUE_H_ #define EMBB_CONTAINERS_BLOCKING_QUEUE_H_
#include <queue>
#include <embb/containers/internal/blocking_push_and_pop_container.h> #include <embb/containers/internal/blocking_push_and_pop_container.h>
#include <queue>
namespace embb { namespace embb {
namespace containers { namespace containers {
...@@ -58,7 +58,7 @@ class BlockingQueue : public BlockingPushAndPopContainer<Type> { ...@@ -58,7 +58,7 @@ class BlockingQueue : public BlockingPushAndPopContainer<Type> {
* in the super class. * in the super class.
*/ */
void SpecializedPush(const Type& element); void SpecializedPush(const Type& element);
/** /**
* Wrapper for pop_front method in the standard library queue. * Wrapper for pop_front method in the standard library queue.
* Implements the corresponding pure virtual method * Implements the corresponding pure virtual method
...@@ -90,12 +90,11 @@ class BlockingQueue : public BlockingPushAndPopContainer<Type> { ...@@ -90,12 +90,11 @@ class BlockingQueue : public BlockingPushAndPopContainer<Type> {
void Dequeue( void Dequeue(
Type& element Type& element
/**< [IN, OUT] Reference to dequeued element*/); /**< [IN, OUT] Reference to dequeued element*/);
}; };
} // namespace containers } // namespace containers
} // namespace embb } // namespace embb
#include <embb/containers/internal/blocking_queue-inl.h> #include <embb/containers/internal/blocking_queue-inl.h>
#endif // EMBB_CONTAINERS_BLOCKING_QUEUE_H_ #endif // EMBB_CONTAINERS_BLOCKING_QUEUE_H_
\ No newline at end of file
...@@ -92,11 +92,10 @@ class BlockingSet { ...@@ -92,11 +92,10 @@ class BlockingSet {
bool Contains( bool Contains(
const Type& element const Type& element
/**< [IN] Reference to the element to search for. */); /**< [IN] Reference to the element to search for. */);
}; };
} } // namespace containers
} } // namespace embb
#include <embb/containers/internal/blocking_set-inl.h> #include <embb/containers/internal/blocking_set-inl.h>
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
#ifndef EMBB_CONTAINERS_BLOCKING_STACK_H_ #ifndef EMBB_CONTAINERS_BLOCKING_STACK_H_
#define EMBB_CONTAINERS_BLOCKING_STACK_H_ #define EMBB_CONTAINERS_BLOCKING_STACK_H_
#include <stack>
#include <embb/containers/internal/blocking_push_and_pop_container.h> #include <embb/containers/internal/blocking_push_and_pop_container.h>
#include <stack>
namespace embb { namespace embb {
namespace containers { namespace containers {
...@@ -86,12 +86,11 @@ class BlockingStack : public BlockingPushAndPopContainer<Type> { ...@@ -86,12 +86,11 @@ class BlockingStack : public BlockingPushAndPopContainer<Type> {
void Pop( void Pop(
Type& element Type& element
/**< [IN, OUT] Reference to popped element*/); /**< [IN, OUT] Reference to popped element*/);
}; };
} // namespace containers } // namespace containers
} // namespace embb } // namespace embb
#include <embb/containers/internal/blocking_stack-inl.h> #include <embb/containers/internal/blocking_stack-inl.h>
#endif // EMBB_CONTAINERS_BLOCKING_STACK_H_ #endif // EMBB_CONTAINERS_BLOCKING_STACK_H_
\ No newline at end of file
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
*/ */
#ifndef EMBB_CONTAINERS_INTERNAL_BLOCKING_MAP_INL_H_ #ifndef EMBB_CONTAINERS_INTERNAL_BLOCKING_MAP_INL_H_
#define EMBB_CONTAINERS_INTERNAL_BLOCKING_SET_INL_H_ #define EMBB_CONTAINERS_INTERNAL_BLOCKING_MAP_INL_H_
#include <map>
namespace embb { namespace embb {
namespace containers { namespace containers {
...@@ -58,7 +60,7 @@ V& BlockingMap<K, V>::operator[](const K& key) { ...@@ -58,7 +60,7 @@ V& BlockingMap<K, V>::operator[](const K& key) {
return internalMap[key]; return internalMap[key];
} }
} } // namespace containers
} } // namespace embb
#endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_MAP_INL_H_ #endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_MAP_INL_H_
\ No newline at end of file
...@@ -31,7 +31,8 @@ namespace embb { ...@@ -31,7 +31,8 @@ namespace embb {
namespace containers { namespace containers {
template<typename T, class Container, class Compare> template<typename T, class Container, class Compare>
void BlockingPriorityQueue<T, Container, Compare>::SpecializedPush(const T& element) { void BlockingPriorityQueue<T, Container, Compare>::SpecializedPush(
const T& element) {
internalQueue.push(element); internalQueue.push(element);
} }
...@@ -56,7 +57,7 @@ bool BlockingPriorityQueue<T, Container, Compare>::IsEmpty() { ...@@ -56,7 +57,7 @@ bool BlockingPriorityQueue<T, Container, Compare>::IsEmpty() {
return internalQueue.empty(); return internalQueue.empty();
} }
} } // namespace containers
} } // namespace embb
#endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_PRIORITY_QUEUE_INL_H_ #endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_PRIORITY_QUEUE_INL_H_
\ No newline at end of file
...@@ -33,15 +33,13 @@ ...@@ -33,15 +33,13 @@
namespace embb { namespace embb {
namespace containers { namespace containers {
// Abstract class, provides a synchronization mechanism for // Abstract class, provides a synchronization mechanism for
// data structures that support push/pop-like methods (e.g. stacks, queues) // data structures that support push/pop-like methods (e.g. stacks, queues)
template < typename Type > template < typename Type >
class BlockingPushAndPopContainer { class BlockingPushAndPopContainer {
typedef embb::base::Mutex Mutex; typedef embb::base::Mutex Mutex;
protected: protected:
Mutex mutex; Mutex mutex;
embb::base::ConditionVariable condition; embb::base::ConditionVariable condition;
...@@ -60,7 +58,7 @@ class BlockingPushAndPopContainer { ...@@ -60,7 +58,7 @@ class BlockingPushAndPopContainer {
condition.NotifyOne(); condition.NotifyOne();
} }
void BlockingPop( Type & element) { void BlockingPop(Type & element) {
embb::base::UniqueLock<Mutex> lock(mutex); embb::base::UniqueLock<Mutex> lock(mutex);
while (IsEmpty()) { while (IsEmpty()) {
...@@ -69,10 +67,9 @@ class BlockingPushAndPopContainer { ...@@ -69,10 +67,9 @@ class BlockingPushAndPopContainer {
SpecializedPop(element); SpecializedPop(element);
} }
}; };
} } // namespace containers
} } // namespace embb
#endif // EMBB_CONTAINERS_BLOCKING_PUSH_AND_POP_CONTAINER_ #endif // EMBB_CONTAINERS_BLOCKING_PUSH_AND_POP_CONTAINER_H_
\ No newline at end of file
...@@ -35,24 +35,24 @@ BlockingSet<T>::BlockingSet() : ...@@ -35,24 +35,24 @@ BlockingSet<T>::BlockingSet() :
internalSet() {} internalSet() {}
template<typename T> template<typename T>
bool BlockingSet<T>::Insert(const T& element){ bool BlockingSet<T>::Insert(const T& element) {
LockGuard lock(mutex); LockGuard lock(mutex);
return internalSet.insert(element).second; return internalSet.insert(element).second;
} }
template<typename T> template<typename T>
bool BlockingSet<T>::Erase(const T& element){ bool BlockingSet<T>::Erase(const T& element) {
LockGuard lock(mutex); LockGuard lock(mutex);
return internalSet.erase(element) > 0; return internalSet.erase(element) > 0;
} }
template<typename T> template<typename T>
bool BlockingSet<T>::Contains(const T& element){ bool BlockingSet<T>::Contains(const T& element) {
LockGuard lock(mutex); LockGuard lock(mutex);
return internalSet.find(element) != internalSet.end(); return internalSet.find(element) != internalSet.end();
} }
} } // namespace containers
} } // namespace embb
#endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_SET_INL_H_ #endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_SET_INL_H_
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment