/*---------------------------------------------------------------------------* Project: NintendoWare File: ut_Signal.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #ifndef NW_UT_SIGNAL_H_ #define NW_UT_SIGNAL_H_ #include #include namespace nw { namespace ut { //---------------------------------------- //! @name シグナル関連 //@{ //--------------------------------------------------------------------------- //! @brief 複数の呼び出しを行い、最後の返り値を返す関数オブジェクトです。 //--------------------------------------------------------------------------- template struct LastValueResult { typedef TResult ResultType; template ResultType operator()(TInputIterator first, TInputIterator last, const TInvoker& invoker) { ResultType result; while (first != last) { result = invoker(*first); ++first; } return result; } }; //--------------------------------------------------------------------------- //! @brief 複数の呼び出しを行い、最後の返り値を返す関数オブジェクトです。 //--------------------------------------------------------------------------- template<> struct LastValueResult { template void operator()(TInputIterator first, TInputIterator last, const TInvoker& invoker) { while (first != last) { invoker(*first); ++first; } } }; //--------------------------------------------------------------------------- //! @brief スロットを生成します。 //! //! @tparam TSlot スロットの型です。 //! @tparam TFunction 関数ポインタまたは、関数オブジェクトの型です。 //! //! @param[in] allocator アロケータです。 //! @param[in] function 関数または、関数オブジェクトです。 //! //! @return 生成したスロットです。 //--------------------------------------------------------------------------- template NW_INLINE TSlot* CreateSlot( os::IAllocator* allocator, TFunction function ) { NW_NULL_ASSERT(allocator); void* memory = allocator->Alloc(sizeof(TSlot)); NW_NULL_ASSERT(memory); return new(memory) TSlot(allocator, function); } //--------------------------------------------------------------------------- //! @brief スロットを破棄する関数オブジェクトです。 //! //! @tparam TSlot スロットの型です。 //--------------------------------------------------------------------------- template struct SlotDestroyer : public std::unary_function { void operator()(TSlot& slot) const { slot->Destroy(); } }; //--------------------------------------------------------------------------- //! @brief コンテナ要素の全てのスロットを破棄するための関数です。 //! //! @tparam TArray 削除するスロットの配列の型です。 //! //! @param[in] array 削除するスロットの配列です。 //--------------------------------------------------------------------------- template NW_INLINE void DestroyAllSlots( TArray& array ) { std::for_each(array.begin(), array.end(), SlotDestroyer()); array.clear(); } //@} // ---------------------------------------------------------------------------- // 自動生成したファイルをインクルードします。 // ---------------------------------------------------------------------------- #include } // namespace ut } // namespace nw #endif // NW_UT_SIGNAL_H_