CPN
Computational Process Networks
FunctionNode.py
Go to the documentation of this file.
1 import sys
2 out = sys.stdout
3 
4 maxparam = 10;
5 
6 out.write("""//=============================================================================
7 // Computational Process Networks class library
8 // Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
9 //
10 // This library is free software; you can redistribute it and/or modify it
11 // under the terms of the GNU Library General Public License as published
12 // by the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
19 //
20 // The GNU Public License is available in the file LICENSE, or you
21 // can write to the Free Software Foundation, Inc., 59 Temple Place -
22 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
23 // World Wide Web at http://www.fsf.org.
24 //=============================================================================
25 /** \\file
26  * \\brief The FunctionNodes are node class that takes as a paramater a
27  * function object.
28  *
29  * The end user should never use these but instead be calling Kernel::CreateFunctionNode
30  * Don't edit this file, edit FunctionNode.py and then manual recreate this file.
31  * Note sections of this file needs to be manually moved to Kernel.h.
32  * This file should not need to change very often.
33  * Things where done this way because C++ doesn't have vararg templates (well
34  * at least the version we are using doesn't).
35  * \\author John Bridgman
36  */
37 
38 #ifndef CPN_FUNCTIONNODE_H
39 #define CPN_FUNCTIONNODE_H
40 #pragma once
41 
42 #include <cpn/common.h>
43 #include <cpn/NodeBase.h>
44 
45 namespace CPN {
46  /**
47  * Nodes that takes a function as an argument and then calls it. This is
48  * to simplify when we have rather simple nodes that have very little data.
49  * \@{
50  */""")
51 
52 for i in range(maxparam):
53  out.write("""
54  template<typename Function""")
55  for a in range(i):
56  out.write(""", typename Argument%d"""%(a + 1));
57  out.write(""">
58  class FunctionNode%(num)d : public NodeBase {
59  public:
60  FunctionNode%(num)d(Kernel &ker, const NodeAttr &attr, Function f"""%{'num':i})
61  for a in range(i):
62  out.write(""", Argument%d a%d"""%(a + 1, a + 1))
63  out.write(""")
64  : NodeBase(ker, attr), function(f)""")
65  for a in range(i):
66  out.write(""", arg%d(a%d)"""%(a + 1, a + 1))
67  out.write("""
68  {}
69  private:
70  void Process() {
71  function(this""")
72  for a in range(i):
73  out.write(""", arg%d"""%(a+1))
74  out.write(""");
75  }
76  Function function;""")
77  for a in range(i):
78  out.write("""
79  Argument%d arg%d;"""%(a+1, a+1))
80  out.write("""
81  };
82 """)
83  out.write(""" template<typename Function""")
84  for a in range(i):
85  out.write(""", typename Argument%d"""%(a + 1))
86  out.write(""">
87  Key_t Kernel::CreateFunctionNode(const std::string &nodename, Function func""")
88  for a in range(i):
89  out.write(""", Argument%(num)d arg%(num)d"""%{'num':a + 1})
90  out.write(""")
91  {
92  Key_t nodekey = context->CreateNodeKey(kernelkey, nodename);
93  NodeAttr attr(nodename, "FunctionNode%(num)d");
94  attr.SetKey(nodekey).SetKernelKey(kernelkey);
95  Sync::AutoReentrantLock arlock(nodelock);
96  shared_ptr<NodeBase> node;
97  node.reset(new FunctionNode%(num)d<Function"""%{'num':i})
98  for a in range(i):
99  out.write(""", Argument%d"""%(a + 1))
100  out.write(""">(*this, attr, func""")
101  for a in range(i):
102  out.write(""", arg%d"""%(a+1))
103  out.write("""));
104  nodemap.insert(std::make_pair(nodekey, node));
105  node->Start();
106  return nodekey;
107  }
108 """)
109 
110 
111 out.write("""
112  /**
113  * \@}
114  */
115  }
116 #endif
117 """)
118 out.write("""
119 #if 0
120 // The following must be copied manually to Kernel.h if it has changed.
121 """)
122 
123 for i in range(maxparam):
124  out.write(""" template<typename Function""")
125  for a in range(i):
126  out.write(""", typename Argument%d"""%(a + 1))
127  out.write(""">
128  Key_t CreateFunctionNode(const std::string &nodename, Function func""")
129  for a in range(i):
130  out.write(""", Argument%(num)d arg%(num)d"""%{'num':a + 1})
131  out.write(""");
132 """)
133 
134 out.write("""#endif
135 """)
136