トップ «前の日記(2006-10-10(火)) 最新 次の日記(2006-10-12(木))» 編集

とた日記


2006-10-11(水) 曇一時雨 安静時心拍数 59 [長年日記]

_ ホストクラスとポリシークラス

先日調べた方法で実装してみました。

% cat policya.h
#ifndef POLICYA_H
#define POLICYA_H
 
class PolicyA
{
protected:
        ~PolicyA();
        int method(int hoge);
        int method(double fuga);
 
};
 
#endif  /* POLICYA_H */
% cat policya.cpp
#include "policya.h"
#include <iostream>
 
PolicyA::~PolicyA()
{
}
 
int PolicyA::method(int hoge)
{
  std::cout << "PolicyA::method(int) " << hoge << std::endl;
 
  return 0;
}
 
int PolicyA::method(double fuga)
{
  std::cout << "PolicyA::method(double) " << fuga << std::endl;
 
  return 0;
}
% cat policyb.h
#ifndef POLICYB_H
#define POLICYB_H
 
class PolicyB
{
protected:
        ~PolicyB();
        int method(int hoge);
        int method(double fuga);
 
};
 
#endif  /* POLICYB_H */
% cat policyb.cpp
#include "policyb.h"
#include <iostream>
 
PolicyB::~PolicyB()
{
}
 
int PolicyB::method(int hoge)
{
  std::cout << "PolicyB::method(int) " << hoge << std::endl;
 
  return 0;
}
 
int PolicyB::method(double fuga)
{
  std::cout << "PolicyB::method(double) " << fuga << std::endl;
 
  return 0;
}
% cat host.h
#ifndef HOST_H
#define HOST_H
 
template <typename Policy>
class Host : public Policy
{
public:
  ~Host();
  int method(int hoge);
  int method(double fuga);
};
 
#endif /* HOST_H */
% cat host.cpp
#include <iostream>
#include "host.h"
#include "policya.h"
#include "policyb.h"
 
template <typename Policy>
Host<Policy>::~Host()
{
}
 
template <typename Policy>
int Host<Policy>::method(int hoge)
{
  Policy::method(hoge);
};
 
template <typename Policy>
int Host<Policy>::method(double fuga)
{
  Policy::method(fuga);
};
 
template class Host<PolicyA>;
template class Host<PolicyB>;
% cat main.cpp
#include <iostream>
#include "host.h"
#include "policya.h"
#include "policyb.h"
 
int main()
{
  Host<PolicyA> A;
  Host<PolicyB> B;
  A.method(1); // "PolicyA::method(int) 1" を表示
  B.method(1.5); // "PolicyB::method(double) 1.5" を表示
 
  return EXIT_SUCCESS;
}

_ portupgrade python

Pythonが2.5にversion upgradeしたので更新しました。

After upgrading of lang/python, you must rebuild all its consumer ports to make them get ready to Python 2.5. To do this, you will need to: pkgdb -uf && cd /usr/ports/lang/python && make upgrade-site-packages

[ports/UPDATING - view - 1.402より引用]

とあるので

# portupgrade python && pkgdb -uf && cd /usr/ports/lang/python && make upgrade-site-packages

として終了です。