chk_factory.hpp

説明を見る。
00001 /*
00002  *  TOPPERS/FDMP Kernel
00003  *      Toyohashi Open Platform for Embedded Real-Time Systems/
00004  *      Function Distributed Multiprocessor Kernel
00005  *
00006  *  Copyright (C) 2005 by Takagi Nobuhisa
00007  * 
00008  *  上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation 
00009  *  によって公表されている GNU General Public License の Version 2 に記
00010  *  述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
00011  *  を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
00012  *  利用と呼ぶ)することを無償で許諾する.
00013  *  (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
00014  *      権表示,この利用条件および下記の無保証規定が,そのままの形でソー
00015  *      スコード中に含まれていること.
00016  *  (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
00017  *      用できる形で再配布する場合には,再配布に伴うドキュメント(利用
00018  *      者マニュアルなど)に,上記の著作権表示,この利用条件および下記
00019  *      の無保証規定を掲載すること.
00020  *  (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
00021  *      用できない形で再配布する場合には,次のいずれかの条件を満たすこ
00022  *      と.
00023  *    (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
00024  *        作権表示,この利用条件および下記の無保証規定を掲載すること.
00025  *    (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
00026  *        報告すること.
00027  *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
00028  *      害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
00029  * 
00030  *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
00031  *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
00032  *  含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
00033  *  接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
00034  * 
00035  */
00036 
00041 #ifndef TOPPERS_ITRON_CHK_FACTORY_HPP_
00042 #define TOPPERS_ITRON_CHK_FACTORY_HPP_
00043 
00044 #include "toppers/itron/kernel_chk.hpp"
00045 #include "toppers/cmdline.hpp"
00046 #include <string>
00047 #include <vector>
00048 #include <boost/shared_ptr.hpp>
00049 #include <boost/mpl/for_each.hpp>
00050 
00051 namespace toppers
00052 {
00053 
00054   class s_record;
00055   class nm_symbol;
00056 
00057   namespace itron
00058   {
00059 
00064     class chk_factory
00065     {
00066     public:
00070       typedef const boost::shared_ptr<chk_factory> ( *builder_type )( const cmdline::option_array&, long );
00074       typedef bool ( *checker_type )( const itron::kernel_chk& chk, const s_record& srec, const nm_symbol& syms );
00075 
00076       chk_factory( const cmdline::option_array& options, long prid );
00080       virtual ~chk_factory() {}
00081 
00086       const boost::shared_ptr<kernel_chk> create_kernel_chk() const { return do_create_kernel_chk(); }
00091       const boost::shared_ptr<std::vector<checker_type> > get_checkers() const { return do_get_checkers(); }
00096       const boost::shared_ptr<cmdline::option_array> options() const { return options_; }
00101       long prid() const { return prid_; }
00102 
00103       static const boost::shared_ptr<chk_factory> build( const cmdline::option_array& options, long prid );
00104       static void register_builder( builder_type builder );
00105       static void clear_builders();
00106       static void global( const boost::shared_ptr<chk_factory>& factory );
00107       static const boost::shared_ptr<chk_factory> global();
00108     protected:
00109       virtual const boost::shared_ptr<kernel_chk> do_create_kernel_chk() const = 0;
00110       virtual const boost::shared_ptr<std::vector<checker_type> > do_get_checkers() const = 0;
00111     private:
00112       static std::vector<builder_type>& builders();
00113       static boost::shared_ptr<chk_factory>& global_factory();
00114 
00115       boost::shared_ptr<cmdline::option_array> options_;
00116       long prid_;
00117     };
00118 
00124     template <class Policy>
00125     class specified_chk_factory : public chk_factory
00126     {
00127     public:
00133       specified_chk_factory( const cmdline::option_array& options, long prid )
00134         : chk_factory( options, prid )
00135       {
00136       }
00137 
00144       static const boost::shared_ptr<chk_factory> build( const cmdline::option_array& options, long prid )
00145       {
00146         boost::shared_ptr<chk_factory> ptr;
00147         if ( Policy::prid_ == prid )
00148         {
00149           ptr.reset( new specified_chk_factory<Policy>( options, prid ) );
00150         }
00151         return ptr;
00152       }
00153     protected:
00154       virtual const boost::shared_ptr<kernel_chk> do_create_kernel_chk() const
00155       {
00156         return boost::shared_ptr<kernel_chk>( new typename Policy::kernel_chk( "" ) );
00157       }
00158       virtual const boost::shared_ptr<std::vector<checker_type> > do_get_checkers() const
00159       {
00160         using namespace boost;
00161         pred_checker pred;
00162         mpl::for_each< typename Policy::sequence >( pred );
00163         return pred.result_;
00164       }
00165     private:
00166       struct pred_checker
00167       {
00168         typedef checker_type result_type;
00169         pred_checker() : result_( new std::vector<result_type> ) {}
00170         template <typename T> void operator()( const T& ) const
00171         {
00172           result_->push_back( &T::check );
00173         }
00174         boost::shared_ptr<std::vector<result_type> > result_;
00175       };
00176     };
00177 
00178   }
00179 }
00180 
00181 #endif  // ! TOPPERS_ITRON_CHK_FACTORY_HPP_

Copyright © 2006 by TAKAGI Nobuhisa.
このページは Wed Apr 12 16:31:56 2006 に Doxygen によって生成されました。