/* -*- mode: c++ -*- 
*/
/* 

    GIFT, a flexible content based image retrieval system.
    Copyright (C) 1998, 1999, 2000 CUI, University of Geneva

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/
#ifndef _CPSETELEMENT
#define _CPSETELEMENT

#include <functional>
#include <iostream>

template<class T>
class CProbabilisticSetElement{
  ///
  T mContent;
  ///
  double mWeight;
  ///
  double mProbability;
  /// difficult to explain
  mutable double mDrawValue;
public:
  ///
  CProbabilisticSetElement<T>():
    mWeight(1),
    mProbability(1)
    {};
  ///
  CProbabilisticSetElement<T>(const T& inContent,
			      double inProbability=1.0,
			      double inWeight=1.0):
    mContent(inContent),
    mWeight(inWeight),
    mProbability(inProbability)
    {
    }
  ///
  void setWeight(double inWeight){
    mWeight=inWeight;
  };
  ///
  void setDrawValue(double inLocation)const{
    mDrawValue=inLocation;
  };
  ///
  void setProbability(double inProbability){
    mProbability=inProbability;
  };
  ///
  void setContent(const T& inContent){
    mContent=inContent;
  };
  ///
  double getWeight()const{
    return mWeight;
  };
  ///
  double getProbability()const{
    return mProbability;
  };
  ///
  double getDrawValue()const{
    return mDrawValue;
  };
  ///
  T getContent()const{
    return mContent;
  };
  ///
  ostream& output(ostream&)const;
};

template<class T>
ostream& CProbabilisticSetElement<T>::output(ostream& outStream)const{
  return outStream << "[CProbabilisticSetElement:"
		   << getProbability()
		   << ","
		   << getWeight()
		   << ","
		   << getContent()
		   << ":CProbabilisticSetElement]";
}


template<class T>
class CSortByProbability_PSE:
  public binary_function<bool,
			   CProbabilisticSetElement<T>,
			   CProbabilisticSetElement<T> >{
public:
  bool operator()(const CProbabilisticSetElement<T>& l,
		  const CProbabilisticSetElement<T>& t)const{
    return 
      l.getProbability()
      <
      t.getProbability();
  };
  bool operator()(const double& l,
		  const CProbabilisticSetElement<T>& t)const{
    return 
      l
      <
      t.getDrawValue();
  };
  bool operator()(const CProbabilisticSetElement<T>& l,
		  const double& t)const{
    return 
      l.getDrawValue()
      <
      t;
  };
};

template<class T>
class CSortByDrawValue_PSE:
  public binary_function<bool,
			   CProbabilisticSetElement<T>,
			   CProbabilisticSetElement<T> >{
public:
  bool operator()(const CProbabilisticSetElement<T>& l,
		  const CProbabilisticSetElement<T>& t)const{
    return 
      l.getDrawValue()
      <
      t.getDrawValue();
  };
  bool operator()(const double& l,
		  const CProbabilisticSetElement<T>& t)const{
    return 
      l
      <
      t.getDrawValue();
  };
  bool operator()(const CProbabilisticSetElement<T>& l,
		  const double& t)const{
    return 
      l.getDrawValue()
      <
      t;
  };
};

template<class T>
class CSortByContent_PSE:
  public binary_function<bool,
  CProbabilisticSetElement<T>,
  CProbabilisticSetElement<T> >{
  public:
  bool operator()(const CProbabilisticSetElement<T>& l,
		  const CProbabilisticSetElement<T>& t)const{
    return 
      l.getContent()
      <
      t.getContent();
  };
  bool operator()(const double& l,
		  const CProbabilisticSetElement<T>& t)const{
    return 
      l
      <
      t.getContent();
  };
  bool operator()(const CProbabilisticSetElement<T>& l,
		  const double& t)const{
    return 
      l.getContent()
      <
      t;
  };
};


#endif

Documentation generated by muellerw@pc7170 on Son Okt 8 16:04:40 CEST 2000