Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

BinaryOp.cpp

Go to the documentation of this file.
00001 /**
00002  * Implementation of the binary operation.
00003  * @file UnaryOp.cpp
00004  * @date July 13, 2001
00005  * @author Ed Bachta
00006  */
00007 
00008 #include "BinaryOp.h"
00009 
00010 /// Default constructor.
00011 BinaryOp::BinaryOp() : 
00012 Implicit()
00013 {
00014   m_f = NULL;
00015   m_g = NULL;
00016 }
00017 
00018 /**
00019  * Explicit constructor.
00020  * @param f First operand.
00021  * @param g Second operand.
00022  */
00023 BinaryOp::BinaryOp(Implicit *f, Implicit *g) :
00024 Implicit()
00025 {
00026   m_f = f;
00027   m_g = g;
00028 } 
00029 
00030 /** 
00031  * qlen Automatically returns total qlen of children.
00032  * Does not need to be overridden if op has no parameters.
00033  * Can be called from subclasses to handle children.
00034  */
00035 int BinaryOp::qlen() 
00036 { 
00037   return ((m_f ? m_f->qlen() : 0) + 
00038           (m_g ? m_g->qlen() : 0)); 
00039 }
00040 
00041 /** 
00042  * setq Automatically sets q of children.
00043  * Does not need to be overridden if op has no parameters.
00044  * Can be called from subclasses to handle children.
00045  */
00046 void BinaryOp::_setq(double *q) 
00047 {
00048   if (m_f) m_f->_setq(q);
00049   if (m_g) m_g->_setq(&q[(m_f ? m_f->qlen() : 0)]);
00050 }
00051 
00052 /**
00053  * getq Automatically gets q of children.
00054  * Does not need to be overridden if op has no parameters.
00055  * Can be called from subclasses to handle children.
00056  */
00057 void BinaryOp::getq(double *q) 
00058 {
00059   if (m_f) m_f->getq(q);
00060   if (m_g) m_g->getq(&q[(m_f ? m_f->qlen() : 0)]);
00061 }
00062 
00063 /** 
00064  * procq Automatically computes df/dq of children.
00065  * Does not need to be overridden if op has no parameters.
00066  * Can be called from subclasses to handle children.
00067  */
00068 void BinaryOp::procq(gmVector3 x, double *q) 
00069 {
00070   if (m_f) m_f->procq(x, q);
00071   if (m_g) m_g->procq(x, &q[(m_f ? m_f->qlen() : 0)]);
00072 }
00073 
00074 /**
00075  * Sets one of the operands of this operation.
00076  * @param   index the operand to set (either 0, or 1)
00077  * @param   child What to set the operand to.
00078  * @returns False if there are not exactly 2 children in the vector.
00079  */
00080 bool BinaryOp::setChild(int index, Implicit* child)
00081 {
00082   bool retval = false;
00083 
00084   if (index == 0)
00085     {
00086       m_f = child;
00087       retval = true;
00088     }
00089   else if (index == 1)
00090     {
00091       m_g = child;
00092       retval = true;
00093     }
00094   
00095   return retval;
00096 }
00097 
00098 /**
00099 * Gets one of the operands of this operation.
00100 * @param   index the operand to get (either 0, or 1)
00101 * @returns child[index].
00102 */
00103 Implicit* BinaryOp::getChild(int index)
00104 {
00105   if (index == 0)
00106     return m_f;
00107   else if (index == 1)
00108     return m_g;
00109   
00110   return NULL;
00111 }
00112 
00113 int BinaryOp::numChildren()
00114 {
00115   int numchild = 0;
00116   if (m_f != NULL)
00117     numchild++;
00118   if (m_g != NULL)
00119     numchild++;
00120 
00121   return numchild;
00122 }
00123 
00124 /** 
00125  * Automatically fills qn with operands parameter names.
00126  * BinaryOp's with no parameters need not redefine getqname().
00127  * BinaryOp's with parameters should set the names of only their parameters
00128  * and then call BinaryOp::getqname(qn) to let it set its operands'
00129  * parameters.
00130  */
00131 void BinaryOp::getqname(char **qn)
00132 {
00133   std::string name;
00134   int fqlen = m_f ? m_f->qlen() : 0;
00135   int gqlen = m_g ? m_g->qlen() : 0;
00136   int myqlen = qlen() - fqlen - gqlen;
00137   
00138   if (m_f) m_f->getqname(&qn[myqlen]);
00139   if (m_g) m_g->getqname(&qn[myqlen + fqlen]);
00140   
00141 #ifdef USENAMES
00142   // Insert the subobject names in parameter names
00143   for (i = myqlen; i < myqlen + fqlen; i++)
00144     {
00145       name = m_f->getObjectName() + ":" + qn[i];
00146       qn[i] = (char *)malloc(name.length()*sizeof(char) + 1);
00147       strcpy(qn[i],name.c_str());
00148     }
00149   
00150   for (i = myqlen + fqlen; i < myqlen + fqlen + gqlen; i++)
00151     {
00152       name = m_g->getObjectName() + ":" + qn[i];
00153       qn[i] = (char *)malloc(name.length()*sizeof(char) + 1);
00154       strcpy(qn[i],name.c_str());
00155     }
00156 #endif
00157 }
00158 

Generated on Mon Jun 28 14:58:13 2004 for Advanced Surface Library by doxygen 1.3.4