/*-------------------------------------------------------------------------- Project: HorizonSDK File: rdt_Queue.h Copyright 2009 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Date:: 2010-04-30#$ $Rev: 15289 $ $Author: hiratsu_daisuke $ *-------------------------------------------------------------------------*/ #include "stdafx.h" #ifndef NN_RDT_QUEUE_H_ #define NN_RDT_QUEUE_H_ #include "rdt_Utility.h" namespace nn { namespace rdt { namespace CTR { /*! @brief これは、キューを表現するテンプレートクラスです。 本当ならSTLを使って済ませたかったのですが、CTR-SDKライブラリ内部では STLを使ってはいけないので、自作することにしました。 */ template class Queue{ public: /*! @brief 初期化します。 */ Queue(void); /*! @brief 解放します。 */ ~Queue(void); /*! @brief キューがカラッポかどうかを判定します。 */ bool IsEmpty(void) const; /*! @brief キューの要素数を得ます。 */ size_t Size(void) const; /*! @brief キューの後方に詰めます。 */ void Push(const T &value); /*! @brief キューの先頭の要素を削除します。 */ void Pop(void); /*! @brief キューの先端の要素を得ます。 */ const T& Front(void) const; /*! @brief キューの末端の要素を得ます。 */ const T& Back(void) const; /*! @brief キューを初期状態に戻します。 */ void Clear(void); /*! @brief デバッグ用機能。中身をプリントします。 */ void PrintDebugInfo(void) const; private: /*! @brief コピーコンストラクタは封印します。 */ Queue (const Queue&); /*! @brief 代入演算子は封印します。 */ Queue& operator=(const Queue&); // 数字の若い方が、先頭側。 T m_array[N]; size_t m_front; // 先頭の要素を指すインデックス size_t m_back; // 後方に詰める時の位置を指すインデックス // m_frontとm_backが等しいとき、キューは「カラ」であるとする。 }; template Queue::Queue(void) { Clear(); } // デストラクタ template Queue::~Queue(void) { } template bool Queue::IsEmpty(void) const { return m_front==m_back; } template size_t Queue::Size(void) const { return (m_back - m_front + N) % N; } template void Queue::Push(const T &value) { ASSERTMSG((m_back + 1) % N != m_front, "You can not Push() anymore because queue is full."); m_array[m_back] = value; m_back = (m_back + 1) % N; } template void Queue::Pop(void) { ASSERTMSG(!IsEmpty(), "You attempt to execute Pop(), but queue is empty."); m_front = (m_front + 1) % N; } template const T& Queue::Front(void) const { return m_array[m_front]; } template const T& Queue::Back(void) const { return m_array[(m_back - 1 + N) % N]; } template void Queue::Clear(void) { m_front = 0; m_back = 0; } // Tが基本型でないと、このPrintDebugInfo()は機能しない…。 template void Queue::PrintDebugInfo(void) const { if(IsEmpty()) { LOG("Queue is empty.\n"); } else { for(u32 i=0; i