1    	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2    	/*                                                                           */
3    	/*                  This file is part of the program and library             */
4    	/*         SCIP --- Solving Constraint Integer Programs                      */
5    	/*                                                                           */
6    	/*    Copyright (C) 2002-2022 Konrad-Zuse-Zentrum                            */
7    	/*                            fuer Informationstechnik Berlin                */
8    	/*                                                                           */
9    	/*  SCIP is distributed under the terms of the ZIB Academic License.         */
10   	/*                                                                           */
11   	/*  You should have received a copy of the ZIB Academic License.             */
12   	/*  along with SCIP; see the file COPYING. If not visit scipopt.org.         */
13   	/*                                                                           */
14   	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15   	
16   	/**@file   objeventhdlr.h
17   	 * @brief  C++ wrapper for event handlers
18   	 * @author Tobias Achterberg
19   	 */
20   	
21   	/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22   	
23   	#ifndef __SCIP_OBJEVENTHDLR_H__
24   	#define __SCIP_OBJEVENTHDLR_H__
25   	
26   	#include <cstring>
27   	
28   	#include "scip/scip.h"
29   	#include "objscip/objcloneable.h"
30   	
31   	namespace scip
32   	{
33   	
34   	/** @brief C++ wrapper for event handlers
35   	 *
36   	 *  This class defines the interface for eventt handlers implemented in C++. Note that there is a pure virtual function
37   	 *  (this function has to be implemented). This function is: scip_exec().
38   	 *
39   	 *  - \ref EVENT "Instructions for implementing an event handler"
40   	 *  - \ref type_event.h "Corresponding C interface"
41   	 */
(1) Event missing_assign: Class "scip::ObjEventhdlr" owns resources that are freed in its destructor but has no user-written assignment operator.
(2) Event free_resource: The destructor frees member "scip_desc_". [details]
(3) Event free_resource: The destructor frees member "scip_name_". [details]
42   	class ObjEventhdlr : public ObjCloneable
43   	{
44   	public:
45   	   /*lint --e{1540}*/
46   	
47   	   /** SCIP data structure */
48   	   SCIP* scip_;
49   	
50   	   /** name of the event handler */
51   	   char* scip_name_;
52   	
53   	   /** description of the event handler */
54   	   char* scip_desc_;
55   	
56   	   /** default constructor */
57   	   ObjEventhdlr(
58   	      SCIP*              scip,               /**< SCIP data structure */
59   	      const char*        name,               /**< name of event handler */
60   	      const char*        desc                /**< description of event handler */
61   	      )
62   	      : scip_(scip),
63   	        scip_name_(0),
64   	        scip_desc_(0)
65   	   {
66   	      /* the macro SCIPduplicateMemoryArray does not need the first argument: */
67   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
68   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
69   	   }
70   	
71   	   /** destructor */
72   	   virtual ~ObjEventhdlr()
73   	   {
74   	      /* the macro SCIPfreeMemoryArray does not need the first argument: */
75   	      /*lint --e{64}*/
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_name_". [details]
76   	      SCIPfreeMemoryArray(scip_, &scip_name_);
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_desc_". [details]
77   	      SCIPfreeMemoryArray(scip_, &scip_desc_);
78   	   }
79   	
80   	   /** destructor of event handler to free user data (called when SCIP is exiting)
81   	    *
82   	    *  @see SCIP_DECL_EVENTFREE(x) in @ref type_event.h
83   	    */
84   	   virtual SCIP_DECL_EVENTFREE(scip_free)
85   	   {  /*lint --e{715}*/
86   	      return SCIP_OKAY;
87   	   }
88   	
89   	   /** initialization method of event handler (called after problem was transformed)
90   	    *
91   	    *  @see SCIP_DECL_EVENTINIT(x) in @ref type_event.h
92   	    */
93   	   virtual SCIP_DECL_EVENTINIT(scip_init)
94   	   {  /*lint --e{715}*/
95   	      return SCIP_OKAY;
96   	   }
97   	
98   	   /** deinitialization method of event handler (called before transformed problem is freed)
99   	    *
100  	    *  @see SCIP_DECL_EVENTEXIT(x) in @ref type_event.h
101  	    */
102  	   virtual SCIP_DECL_EVENTEXIT(scip_exit)
103  	   {  /*lint --e{715}*/
104  	      return SCIP_OKAY;
105  	   }
106  	
107  	   /** solving process initialization method of event handler (called when branch and bound process is about to begin)
108  	    *
109  	    *  @see SCIP_DECL_EVENTINITSOL(x) in @ref type_event.h
110  	    */
111  	   virtual SCIP_DECL_EVENTINITSOL(scip_initsol)
112  	   {  /*lint --e{715}*/
113  	      return SCIP_OKAY;
114  	   }
115  	
116  	   /** solving process deinitialization method of event handler (called before branch and bound process data is freed)
117  	    *
118  	    *  @see SCIP_DECL_EVENTEXITSOL(x) in @ref type_event.h
119  	    */
120  	   virtual SCIP_DECL_EVENTEXITSOL(scip_exitsol)
121  	   {  /*lint --e{715}*/
122  	      return SCIP_OKAY;
123  	   }
124  	
125  	   /** frees specific constraint data
126  	    *
127  	    *  @see SCIP_DECL_EVENTDELETE(x) in @ref type_event.h
128  	    */
129  	   virtual SCIP_DECL_EVENTDELETE(scip_delete)
130  	   {  /*lint --e{715}*/
131  	      return SCIP_OKAY;
132  	   }
133  	
134  	   /** execution method of event handler
135  	    *
136  	    *  @see SCIP_DECL_EVENTEXEC(x) in @ref type_event.h
137  	    */
138  	   virtual SCIP_DECL_EVENTEXEC(scip_exec) = 0;
139  	};
140  	
141  	} /* namespace scip */
142  	
143  	
144  	
145  	/** creates the event handler for the given event handler object and includes it in SCIP
146  	 *
147  	 *  The method should be called in one of the following ways:
148  	 *
149  	 *   1. The user is resposible of deleting the object:
150  	 *       SCIP_CALL( SCIPcreate(&scip) );
151  	 *       ...
152  	 *       MyEventhdlr* myeventhdlr = new MyEventhdlr(...);
153  	 *       SCIP_CALL( SCIPincludeObjEventhdlr(scip, &myeventhdlr, FALSE) );
154  	 *       ...
155  	 *       SCIP_CALL( SCIPfree(&scip) );
156  	 *       delete myeventhdlr;    // delete eventhdlr AFTER SCIPfree() !
157  	 *
158  	 *   2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
159  	 *       SCIP_CALL( SCIPcreate(&scip) );
160  	 *       ...
161  	 *       SCIP_CALL( SCIPincludeObjEventhdlr(scip, new MyEventhdlr(...), TRUE) );
162  	 *       ...
163  	 *       SCIP_CALL( SCIPfree(&scip) );  // destructor of MyEventhdlr is called here
164  	 */
165  	SCIP_EXPORT
166  	SCIP_RETCODE SCIPincludeObjEventhdlr(
167  	   SCIP*                 scip,               /**< SCIP data structure */
168  	   scip::ObjEventhdlr*   objeventhdlr,       /**< event handler object */
169  	   SCIP_Bool             deleteobject        /**< should the event handler object be deleted when eventhdlristic is freed? */
170  	   );
171  	
172  	/** returns the eventhdlr object of the given name, or 0 if not existing */
173  	SCIP_EXPORT
174  	scip::ObjEventhdlr* SCIPfindObjEventhdlr(
175  	   SCIP*                 scip,               /**< SCIP data structure */
176  	   const char*           name                /**< name of event handler */
177  	   );
178  	
179  	/** returns the eventhdlr object for the given event handler */
180  	SCIP_EXPORT
181  	scip::ObjEventhdlr* SCIPgetObjEventhdlr(
182  	   SCIP*                 scip,               /**< SCIP data structure */
183  	   SCIP_EVENTHDLR*       eventhdlr           /**< event handler */
184  	   );
185  	
186  	#endif
187