Scippy

SCIP

Solving Constraint Integer Programs

objmessagehdlr.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2014 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 email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objmessagehdlr.cpp
17  * @brief C++ wrapper for message handlers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <cassert>
24 
25 #include "objmessagehdlr.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** message handler data */
35 struct SCIP_MessagehdlrData
36 {
37  scip::ObjMessagehdlr* objmessagehdlr; /**< message handler object */
38  SCIP_Bool deleteobject; /**< should the message handler object be deleted when message handler is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of file reader
46  */
47 
48 extern "C"
49 {
50 /** warning message print method of message handler */
51 static
52 SCIP_DECL_MESSAGEWARNING(messagehdlrWarningObj)
53 { /*lint --e{715}*/
54  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
55 
56  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
57  assert(messagehdlrdata != NULL);
58  assert(messagehdlrdata->objmessagehdlr != NULL);
59 
60  /* call virtual method of messagehdlr object */
61  messagehdlrdata->objmessagehdlr->scip_warning(messagehdlr, file, msg);
62 }
63 
64 
65 /** dialog message print method of message handler */
66 static
67 SCIP_DECL_MESSAGEDIALOG(messagehdlrDialogObj)
68 { /*lint --e{715}*/
69  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
70 
71  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
72  assert(messagehdlrdata != NULL);
73  assert(messagehdlrdata->objmessagehdlr != NULL);
74 
75  /* call virtual method of messagehdlr object */
76  messagehdlrdata->objmessagehdlr->scip_dialog(messagehdlr, file, msg);
77 }
78 
79 
80 /** info message print method of message handler */
81 static
82 SCIP_DECL_MESSAGEINFO(messagehdlrInfoObj)
83 { /*lint --e{715}*/
84  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
85 
86  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
87  assert(messagehdlrdata != NULL);
88  assert(messagehdlrdata->objmessagehdlr != NULL);
89 
90  /* call virtual method of messagehdlr object */
91  messagehdlrdata->objmessagehdlr->scip_info(messagehdlr, file, msg);
92 }
93 
94 /** destructor of message handler to free message handler data */
95 static
97 { /*lint --e{715}*/
98  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
99 
100  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
101  assert(messagehdlrdata != NULL);
102  assert(messagehdlrdata->objmessagehdlr != NULL);
103 
104  /* call virtual method of messagehdlr object */
105  SCIP_CALL( messagehdlrdata->objmessagehdlr->scip_free(messagehdlr) );
106 
107  /* free message handler object */
108  if( messagehdlrdata->deleteobject )
109  delete messagehdlrdata->objmessagehdlr;
110 
111  /* free message handler data */
112  delete messagehdlrdata;
113  SCIP_CALL( SCIPmessagehdlrSetData(messagehdlr, NULL) ); /*lint !e64*/
114 
115  return SCIP_OKAY;
116 }
117 }
118 
119 
120 
121 /*
122  * message handler specific interface methods
123  */
124 
125 /** creates the message handler for the given message handler object */
127  SCIP_MESSAGEHDLR** messagehdlr, /**< pointer to store the message handler */
128  scip::ObjMessagehdlr* objmessagehdlr, /**< message handler object */
129  SCIP_Bool deleteobject /**< should the message handler object be deleted when message handler is freed? */
130  )
131 {
132  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
133  SCIP_RETCODE retcode;
134 
135  /* create file messagehdlr data */
136  messagehdlrdata = new SCIP_MESSAGEHDLRDATA;
137  messagehdlrdata->objmessagehdlr = objmessagehdlr;
138  messagehdlrdata->deleteobject = deleteobject;
139 
140  /* create message handler */
141  retcode = SCIPmessagehdlrCreate(messagehdlr, objmessagehdlr->scip_bufferedoutput_, (const char*)NULL, FALSE,
142  messagehdlrWarningObj, messagehdlrDialogObj, messagehdlrInfoObj,
143  messagehdlrFree, messagehdlrdata); /*lint !e429*/
144 
145  if( retcode != SCIP_OKAY )
146  {
147  /* free message handler object */
148  if( messagehdlrdata->deleteobject )
149  delete messagehdlrdata->objmessagehdlr;
150 
151  delete messagehdlrdata;
152  SCIP_CALL( retcode );
153  }
154 
155  return SCIP_OKAY; /*lint !e429 !e593*/
156 }
157 
158 /** returns the message handler object for the given message handler */
160  SCIP_MESSAGEHDLR* messagehdlr /**< message handler */
161  )
162 {
163  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
164 
165  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
166  assert(messagehdlrdata != NULL);
167 
168  return messagehdlrdata->objmessagehdlr;
169 }
170 
171