1 /*
2  *  Open BEAGLE
3  *  Copyright (C) 2001-2007 by Christian Gagne and Marc Parizeau
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2.1 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  *  Contact:
20  *  Laboratoire de Vision et Systemes Numeriques
21  *  Departement de genie electrique et de genie informatique
22  *  Universite Laval, Quebec, Canada, G1K 7P4
23  *  http://vision.gel.ulaval.ca
24  *
25  */
26 
27 /*!
28  *  \file   beagle/GP/src/Xor.cpp
29  *  \brief  Source code of class GP::Xor.
30  *  \author Christian Gagne
31  *  \author Marc Parizeau
32  *  $Revision: 1.10.2.1 $
33  *  $Date: 2007/05/09 01:51:07 $
34  */
35 
36 #include "beagle/GP.hpp"
37 
38 #ifdef BEAGLE_HAVE_RTTI
39 #include <typeinfo>
40 #endif // BEAGLE_HAVE_RTTI
41 
42 using namespace Beagle;
43 
44 
45 /*!
46  *  \brief Construct a new boolean XOR primitive.
47  *  \param inName Name of the addition primitive.
48  */
Xor(Beagle::string inName)49 GP::Xor::Xor(Beagle::string inName) :
50   Beagle::GP::Primitive(2, inName)
51 { }
52 
53 
54 #ifdef BEAGLE_HAVE_RTTI
55 
56 /*!
57  *  \brief  Return the tag of the type of data needed as input for the primitive Xor.
58  *  \param  inN Index of the argument to get the type tag.
59  *  \param  ioContext Evolutionary context.
60  *  \return Type_info (RTTI) tagging the data type needed.
61  *  \throw  AssertException If the index inN given is greater than 1.
62  */
getArgType(unsigned int inN,GP::Context & ioContext) const63 const std::type_info* GP::Xor::getArgType(unsigned int inN, GP::Context& ioContext) const
64 {
65   Beagle_StackTraceBeginM();
66   Beagle_AssertM(inN<2);
67   return &typeid(Bool);
68   Beagle_StackTraceEndM("const std::type_info* GP::Xor::getArgType(unsigned int inN, GP::Context& ioContext) const");
69 }
70 
71 
72 /*!
73  *  \brief  Return the tag of the type of data return by primitive Xor.
74  *  \param  ioContext Evolutionary context.
75  *  \return Type_info (RTTI) tagging the data type returned.
76  */
getReturnType(GP::Context & ioContext) const77 const std::type_info* GP::Xor::getReturnType(GP::Context& ioContext) const
78 {
79   Beagle_StackTraceBeginM();
80   return &typeid(Bool);
81   Beagle_StackTraceEndM("const std::type_info* GP::Xor::getReturnType(GP::Context& ioContext) const");
82 }
83 
84 #endif // BEAGLE_HAVE_RTTI
85 
86 
87 /*!
88  *  \brief Execute the characteristic operation of logical AND between two bools.
89  *  \param outResult Result of the logical XOR.
90  *  \param ioContext Evolutionary context.
91  */
execute(GP::Datum & outResult,GP::Context & ioContext)92 void GP::Xor::execute(GP::Datum& outResult, GP::Context& ioContext)
93 {
94   Beagle_StackTraceBeginM();
95   Bool& lResult = castObjectT<Bool&>(outResult);
96   Bool lArg2;
97   get1stArgument(lResult, ioContext);
98   get2ndArgument(lArg2, ioContext);
99   lResult = lResult != lArg2;
100   Beagle_StackTraceEndM("void GP::Xor::execute(GP::Datum& outResult, GP::Context& ioContext)");
101 }
102