Click here to Skip to main content
15,885,757 members
Articles / Database Development / SQL Server

EpOraLibrary - A lightweight C++ wrapper over Oracle's OCI library

Rate me:
Please Sign up or sign in to vote.
4.94/5 (14 votes)
2 Jun 2014MIT8 min read 53.8K   805   43  
This is an alternative project of "OraLib - a lightweight C++ wrapper over Oracle's OCI library"
/*! 
@file epThreadSafePQueue.h
@author Woong Gyu La a.k.a Chris. <juhgiyo@gmail.com>
		<http://github.com/juhgiyo/eplibrary>
@date September 02, 2010
@brief ThreadSafe Priority Queue Interface
@version 2.0

@section LICENSE

The MIT License (MIT)

Copyright (c) 2008-2013 Woong Gyu La <juhgiyo@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@section DESCRIPTION

An Interface for Thread Safe Priority Queue.

*/
#ifndef __EP_THREAD_SAFE_PQUEUE_H__
#define __EP_THREAD_SAFE_PQUEUE_H__
#include "epLib.h"
#include "epThreadSafeQueue.h"
#include "epBinarySearch.h"

namespace epl
{
	/*! 
	@class ThreadSafePQueue epThreadSafePQueue.h
	@brief A class for Thread Safe Priority Queue.
	*/
	template <typename DataType, typename Compare=CompClass<DataType> >
	class ThreadSafePQueue:public ThreadSafeQueue<DataType>
	{
	public:
		/*!
		Default Constructor

		Initializes the priority queue
		@param[in] lockPolicyType The lock policy
		*/
		ThreadSafePQueue(LockPolicy lockPolicyType=EP_LOCK_POLICY);

		/*!
		Default Copy Constructor

		Initializes the queue
		@param[in] b the second object
		*/
		ThreadSafePQueue(const ThreadSafePQueue& b);

		/*!
		Default Destructor

		Destroy the priority queue
		*/
		virtual ~ThreadSafePQueue();

		/*!
		Assignment Operator Overloading

		the ThreadSafeQueue set as given ThreadSafeQueue b
		@param[in] b right side of ThreadSafeQueue
		@return this object
		*/
		ThreadSafePQueue & operator=(const ThreadSafePQueue&b);

		/*!
		Insert the new item into the priority queue.
		@param[in] data The inserting data.
		*/
		virtual void Push(DataType const &data);

	};

	template <typename DataType, typename Compare>
	ThreadSafePQueue<DataType,Compare>::ThreadSafePQueue(LockPolicy lockPolicyType) :ThreadSafeQueue<DataType>(lockPolicyType)
	{
	}
	template <typename DataType, typename Compare>
	ThreadSafePQueue<DataType,Compare>::ThreadSafePQueue(const ThreadSafePQueue& b):ThreadSafeQueue<DataType>(b)
	{
	}
	template <typename DataType, typename Compare>
	ThreadSafePQueue<DataType,Compare>::~ThreadSafePQueue()
	{
	}
	
	template <typename DataType, typename Compare>
	ThreadSafePQueue<DataType,Compare> & ThreadSafePQueue<DataType,Compare>::operator=(const ThreadSafePQueue&b)
	{
		if(this != &b)
		{
			ThreadSafeQueue::operator =(b);
		}
		return *this;
	}

	template <typename DataType, typename Compare>
	void ThreadSafePQueue<DataType,Compare>::Push(DataType const & data)
	{
		LockObj lock(m_queueLock);
		DataType* retVal=NULL;
		if(m_queue.size())
		{
			size_t retIdx;
			if(BinarySearch(data,&m_queue.at(0),m_queue.size(),Compare::CompFunc,retIdx))
				EP_ASSERT_EXPR(0,_T("Same Object already in the Queue!!"));
			m_queue.insert(m_queue.begin()+retIdx,data);
		}
		else
		{
			m_queue.push_back(data);
		}

	}
}


#endif //__EP_THREAD_SAFE_PQUEUE_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
United States United States
Woong Gyu La had been working as a software developer for over 8 years.
His personal interests are improving his personal projects,

EpLibrary (Visual C++ Utility Library)
https://github.com/juhgiyo/EpLibrary[^]

EpOraLibrary (Oracle OCI Wrapper Library for Visual C++)
https://github.com/juhgiyo/EpOraLibrary[^]

EpServerEngine (Visual C++ WinSock Server/Client Engine)
https://github.com/juhgiyo/EpServerEngine[^]

And other projects can be found at
https://github.com/juhgiyo?tab=repositories[^]

Finally, my other articles can be found at
http://www.codeproject.com/Articles/juhgiyo#articles[^]

You can contact me at juhgiyo@gmail.com[^]

Comments and Discussions