/[ascend]/trunk/ascxx/solverhooks.h
ViewVC logotype

Contents of /trunk/ascxx/solverhooks.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2649 - (show annotations) (download) (as text)
Wed Dec 12 12:39:25 2012 UTC (11 years, 9 months ago) by jpye
File MIME type: text/x-chdr
File size: 3396 byte(s)
Fixing GPL header, removing postal address (rpmlint incorrect-fsf-address)
1 /* ASCEND modelling environment
2 Copyright (C) 2010 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *//** @file
17 Implementation of solver hooks on the C++ side, for accessing by the
18 'slvreq.h' language features (SOLVER, OPTION, SOLVE) in ASCEND METHODS.
19 This code allows us to make the GUI do things upon instruction from methods
20 being run in the MODEL.
21
22 See also SlvReqHooks in ascend/compiler/slvreq.h.
23 */
24
25 #ifndef ASCXX_SOLVERHOOKS_H
26 #define ASCXX_SOLVERHOOKS_H
27
28 #include "config.h"
29 #include "value.h"
30
31 class SolverReporter;
32 class Simulation;
33
34 extern "C"{
35 #include <ascend/general/platform.h>
36 #include <ascend/compiler/slvreq.h>
37 };
38
39 extern "C"{
40 SlvReqSetSolverFn ascxx_slvreq_set_solver;
41 SlvReqSetOptionFn ascxx_slvreq_set_option;
42 SlvReqDoSolveFn ascxx_slvreq_do_solve;
43 };
44
45 /**
46 A C++ structure to handle the calling of slvreq hooks by METHODs. This
47 has to provide a mechanism that allows access to both the pure C++ API
48 (see testslvreq.cpp) as well as the Python/PyGTK GUI. So we will allow
49 subclassing of SolverHooks as SolverHooksPython for that case.
50 */
51 class SolverHooks{
52 private:
53 SolverReporter *R;
54 public:
55 SolverHooks(SolverReporter *reporter = NULL);
56 SolverHooks(SolverHooks &old);
57 virtual ~SolverHooks();
58
59 /// C++ function that will be called as a result of a 'SOLVER' command
60 virtual int setSolver(const char *solvername, Simulation *S);
61
62 /// C++ function that will be called as a result of a 'OPTION' command
63 virtual int setOption(const char *optionname, Value val1, Simulation *S);
64
65 /// C++ function that will be called as a result of a 'SOLVE' command
66 virtual int doSolve(Instance *i, Simulation *S);
67
68 SolverReporter *getSolverReporter();
69
70 void assign(Simulation *S);
71 };
72
73 /**
74 A 'manager' singleton for dealing with the assignment of 'slvreq' hooks
75 to Simulation objects in the C++ layer. This needs to be a singleton because
76 the Type::getSimulation method needs to be able to grab the solver hooks
77 from an as-it-were global object of some sort. But we also need to ability
78 to reassign different solver hooks in the C++ layer, because the Python
79 GUI will use different hooks to the pure C++ API (see testslvreq.cpp).
80
81 Note that if no setHooks() call has been made before the first call to
82 getHooks(), the SetHooksManager will assign a default C++ SolverHooks
83 object. Therefore, for users of Python or other possible interfaces based
84 on this code, you must make sure you first call
85
86 SolverHooksManager::Instance()->setHooks(mysolverhooksobject);
87 */
88 class SolverHooksManager{
89 private:
90 bool own_hooks;
91 SolverHooks *hooks;
92 SolverHooksManager(); // This class will be a singleton
93 ~SolverHooksManager();
94 static SolverHooksManager *_instance;
95
96 public:
97 static SolverHooksManager *Instance();
98 void setHooks(SolverHooks *hooks);
99 SolverHooks *getHooks();
100 };
101
102
103 #endif

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22