[ create a new paste ] login | about

Link: http://codepad.org/7t7xN7Iy    [ raw code | output | fork ]

C++, pasted on Aug 16:
/******* 基本構造からgetterが埋めこまれてるため、getterを排除した形でインターフェースの再定義 **********/
struct 科目Receiver{virtual void Receiv科目( int 単位, bool 既修, bool 履修 ) = 0;};
class 科目
{
       int 単位;
       bool 既修, 履修;
public:
       void operator>>( 科目Receiver &receiver ){ receiver.Receiv科目( 単位, 既修, 履修 ); }
       /* 科目の入力条件は不明なので入力は省略 */
};

struct 判定ルールReciever
{
       virtual void Receiv単位ルール( std::list<科目> &科目List, int 必要単位数 ) = 0;
       virtual void Receiv科目ルール( std::list<科目> &科目List, int 必要科目数 ) = 0;
};

class 判定ルール
{
       std::list<科目> 科目List;
       bool is単位;
       int 必要単位数;
       int 必要科目数;
public:
       void operator>>( 判定ルールReciever &receiver )
       {
              if( is単位 )
                     receiver->Receiv単位ルール( 科目List, 必要単位数 );
              else
                     receiver->Receiv科目ルール( 科目List, 必要科目数 );
       }
       /* ルールの入力条件は不明なので入力は省略 */
};

/*
bool型で返しても条件分岐に使われるのがオチなので、実行可否を判断する関数型オブジェクトで代用する
どうしてもbool型が欲しいなら、Exceutableを継承しboolを生成するクラスを作る。
*/
struct Exceutable{virtual void operator()(void) = 0;};


/******************************* ここからが新たにつくる判定処理 *******************************/
class 集計判定:public 科目Receiver
{
       int 必要数,合計;
       boost::function<void(int&,int)> f;
       集計判定( int 必要数, boost::function<void(int&,int)> effect ):必要数( 必要数 ),合計(0),f(effect){}
public:
       void operator>>( Exceutable &command ){ if( 必要数 <= 合計 ) command(); }
       void Receiv科目( int 単位, bool 既修, bool 履修 ){if( 既修 || 履修 ) f( 合計, 単位 )}
};

class 判定:public 判定ルールReciever
{
       boost::shared_ptr<集計判定> 判定結果;
public:
       void operator>>( Exceutable &command ){ *判定結果 >> command; }
       void Receiv単位ルール( std::list<科目> &科目List, int 必要数 )
       {
              using namespace boost::lambda;
              判定結果 = boost::shared_ptr<集計判定>( new 集計判定( 必要数, _1 += _2 ) );
              boost::for_each( 科目List, *判定結果 );
       }
       void Receiv科目ルール( std::list<科目> &科目List, int 必要数 )
       {
              using namespace boost::lambda;
              判定結果 = boost::shared_ptr<集計判定>( new 集計判定( 必要数, (++_1, _2 ) );
              boost::for_each( 科目List, *判定結果 );
       }
};

int main()
{
       判定ルール ルール;
       判定 判定;
       ルール >> 判定;

       return 0;
}


Output:
1
2
Line 2: error: stray '\347' in program
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: