File indexing completed on 2024-12-22 04:17:53

0001 /***************************************************************************
0002                               enodefactory.cpp
0003                                  ----------      
0004     begin                : Feb 12 2004
0005     copyright            : (C) 2004 The University of Toronto
0006     email                : netterfield@astro.utoronto.ca
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "enodefactory.h"
0019 #include "enodes.h"
0020 
0021 using namespace Equations;
0022 using namespace std;
0023 
0024 //extern "C" {
0025 
0026 #define CreateFactory(x)                         \
0027         void *New##x(void *left, void *right) {  \
0028           Node *l = static_cast<Node*>(left);    \
0029           Node *r = static_cast<Node*>(right);   \
0030           return new x(l, r);                    \
0031         }
0032 
0033 CreateFactory(Addition)
0034 CreateFactory(Subtraction)
0035 CreateFactory(Multiplication)
0036 CreateFactory(Division)
0037 CreateFactory(Modulo)
0038 CreateFactory(Power)
0039 CreateFactory(BitwiseAnd)
0040 CreateFactory(BitwiseOr)
0041 CreateFactory(LogicalAnd)
0042 CreateFactory(LogicalOr)
0043 CreateFactory(LessThan)
0044 CreateFactory(LessThanEqual)
0045 CreateFactory(GreaterThan)
0046 CreateFactory(GreaterThanEqual)
0047 CreateFactory(EqualTo)
0048 CreateFactory(NotEqualTo)
0049 
0050 
0051 #undef CreateFactory
0052 
0053 void *NewData(Kst::ObjectStore *store, char *name) {
0054   return new DataNode(store, name);
0055 }
0056 
0057 
0058 void *NewIdentifier(char *name) {
0059   return new Identifier(name);
0060 }
0061 
0062 
0063 void *NewFunction(char *name, void *args) {
0064   return new Function(name, static_cast<ArgumentList*>(args));
0065 }
0066 
0067 
0068 void *NewNumber(double n) {
0069   return new Number(n);
0070 }
0071 
0072 
0073 void *NewArgumentList() {
0074   return new ArgumentList();
0075 }
0076 
0077 
0078 void AppendArgument(void *list, void *arg) {
0079   if (list && arg) {
0080     static_cast<ArgumentList*>(list)->appendArgument(static_cast<Node*>(arg));
0081   }
0082 }
0083 
0084 
0085 void *NewNot(void *n) {
0086   return new LogicalNot(static_cast<Node*>(n));
0087 }
0088 
0089 
0090 void *NewNegation(void *n) {
0091   return new Negation(static_cast<Node*>(n));
0092 }
0093 
0094 
0095 void DeleteNode(void *n) {
0096   delete static_cast<Node*>(n);
0097 }
0098 
0099 
0100 void ParenthesizeNode(void *n) {
0101   static_cast<Node*>(n)->parenthesize();
0102 }
0103 
0104 
0105 //}
0106 
0107 
0108 // vim: ts=2 sw=2 et