conditionalpdf.h
Go to the documentation of this file.
00001 // $Id: conditionalpdf.h 30606 2009-10-02 10:01:02Z tdelaet $
00002 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
00003  /***************************************************************************
00004  *   This library is free software; you can redistribute it and/or         *
00005  *   modify it under the terms of the GNU General Public                   *
00006  *   License as published by the Free Software Foundation;                 *
00007  *   version 2 of the License.                                             *
00008  *                                                                         *
00009  *   As a special exception, you may use this file as part of a free       *
00010  *   software library without restriction.  Specifically, if other files   *
00011  *   instantiate templates or use macros or inline functions from this     *
00012  *   file, or you compile this file and link it with other files to        *
00013  *   produce an executable, this file does not by itself cause the         *
00014  *   resulting executable to be covered by the GNU General Public          *
00015  *   License.  This exception does not however invalidate any other        *
00016  *   reasons why the executable file might be covered by the GNU General   *
00017  *   Public License.                                                       *
00018  *                                                                         *
00019  *   This library is distributed in the hope that it will be useful,       *
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00022  *   Lesser General Public License for more details.                       *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public             *
00025  *   License along with this library; if not, write to the Free Software   *
00026  *   Foundation, Inc., 59 Temple Place,                                    *
00027  *   Suite 330, Boston, MA  02111-1307  USA                                *
00028  *                                                                         *
00029  ***************************************************************************/
00030 #ifndef __CONDITIONAL_PDF__
00031 #define __CONDITIONAL_PDF__
00032 
00033 #include "pdf.h"
00034 #include <vector>
00035 #include <cassert>
00036 namespace BFL
00037 {
00038 
00040 
00049   template <typename Var, typename CondArg> class ConditionalPdf : public Pdf<Var>
00050     {
00051     public:
00053 
00058       ConditionalPdf(int dimension=0, unsigned int num_conditional_arguments=0);
00059 
00060       // Default copy constructor will do
00061 
00063       virtual ~ConditionalPdf();
00064 
00066       virtual ConditionalPdf<Var,CondArg>* Clone() const;
00067 
00069 
00071       unsigned int NumConditionalArgumentsGet() const;
00072 
00074 
00079       virtual void NumConditionalArgumentsSet(unsigned int numconditionalarguments);
00080 
00082 
00085       const std::vector<CondArg>& ConditionalArgumentsGet() const;
00086 
00088 
00091       virtual void ConditionalArgumentsSet(std::vector<CondArg> ConditionalArguments);
00092 
00094 
00097       const CondArg& ConditionalArgumentGet(unsigned int n_argument) const;
00098 
00100 
00104       virtual void ConditionalArgumentSet(unsigned int n_argument, const CondArg& argument);
00105 
00106     private:
00108       unsigned int _NumConditionalArguments;
00110       std::vector<CondArg> _ConditionalArguments;
00111     };
00112 
00113 
00114   // constructor
00115   template<typename Var, typename CondArg>
00116     ConditionalPdf<Var,CondArg>::ConditionalPdf(int dim, unsigned int num_args)
00117     : Pdf<Var>(dim)
00118     , _NumConditionalArguments(num_args)
00119     , _ConditionalArguments(num_args)
00120     {}
00121 
00122   // destructor
00123   template<typename Var, typename CondArg>
00124     ConditionalPdf<Var,CondArg>::~ConditionalPdf()
00125     {}
00126 
00127   //Clone function
00128   template<typename Var, typename CondArg>
00129     ConditionalPdf<Var,CondArg>* ConditionalPdf<Var,CondArg>::Clone() const
00130   {
00131       return new ConditionalPdf(*this);
00132   }
00133 
00134   template<typename Var, typename CondArg> inline unsigned int
00135     ConditionalPdf<Var,CondArg>::NumConditionalArgumentsGet() const
00136     {
00137       return _NumConditionalArguments;
00138     }
00139 
00140   template<typename Var, typename CondArg> inline void
00141     ConditionalPdf<Var,CondArg>::NumConditionalArgumentsSet(unsigned int numconditionalarguments)
00142     {
00143       if (numconditionalarguments != _NumConditionalArguments)
00144         {
00145           _NumConditionalArguments = numconditionalarguments;
00146           this->_ConditionalArguments.resize(_NumConditionalArguments);
00147         }
00148     }
00149 
00150 
00151   template<typename Var, typename CondArg> const std::vector<CondArg>&
00152     ConditionalPdf<Var,CondArg>::ConditionalArgumentsGet() const
00153     {
00154       return _ConditionalArguments;
00155     }
00156 
00157   template<typename Var, typename CondArg> void
00158     ConditionalPdf<Var,CondArg>::ConditionalArgumentsSet(std::vector<CondArg> condargs)
00159     {
00160       assert (condargs.size() == _NumConditionalArguments);
00161       this->_ConditionalArguments = condargs;
00162     }
00163 
00164   template<typename Var, typename CondArg> const CondArg&
00165     ConditionalPdf<Var,CondArg>::ConditionalArgumentGet(unsigned int n_argument) const
00166     {
00167       assert( n_argument < _NumConditionalArguments );
00168       // index of conditional arguments of ConditionalPdf out of range
00169       return _ConditionalArguments[n_argument];
00170     }
00171 
00172   template<typename Var, typename CondArg> void
00173     ConditionalPdf<Var,CondArg>::ConditionalArgumentSet(unsigned int n_argument,
00174                                                         const CondArg& argument)
00175     {
00176       assert ( n_argument < _NumConditionalArguments );
00177       // index of conditional arguments of ConditionalPdf out of range
00178       this->_ConditionalArguments[n_argument]= argument;
00179     }
00180 
00181 } // End namespace
00182 #endif // __CONDITIONAL_PDF__


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Sun Oct 5 2014 22:29:52