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-2024 Zuse Institute Berlin (ZIB) */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file objmessagehdlr.cpp
26  * @brief C++ wrapper for message handlers
27  * @author Tobias Achterberg
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #include <cassert>
33 
34 #include "objmessagehdlr.h"
35 
36 
37 
38 
39 /*
40  * Data structures
41  */
42 
43 /** message handler data */
44 struct SCIP_MessagehdlrData
45 {
46  scip::ObjMessagehdlr* objmessagehdlr; /**< message handler object */
47  SCIP_Bool deleteobject; /**< should the message handler object be deleted when message handler is freed? */
48 };
49 
50 
51 
52 
53 /*
54  * Callback methods of file reader
55  */
56 
57 extern "C"
58 {
59 /** error message print method of message handler */
60 static
61 SCIP_DECL_ERRORPRINTING(messagehdlrErrorObj)
62 {
63  assert( data != 0 );
64 
65  scip::ObjMessagehdlr* objmessagehdlr = static_cast<scip::ObjMessagehdlr*>(data);
66 
67  objmessagehdlr->scip_error(0, file, msg);
68 }
69 
70 /** warning message print method of message handler */
71 static
72 SCIP_DECL_MESSAGEWARNING(messagehdlrWarningObj)
73 { /*lint --e{715}*/
74  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
75 
76  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
77  assert(messagehdlrdata != NULL && messagehdlrdata->objmessagehdlr != NULL);
78 
79  /* call virtual method of messagehdlr object */
80  messagehdlrdata->objmessagehdlr->scip_warning(messagehdlr, file, msg);
81 }
82 
83 
84 /** dialog message print method of message handler */
85 static
86 SCIP_DECL_MESSAGEDIALOG(messagehdlrDialogObj)
87 { /*lint --e{715}*/
88  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
89 
90  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
91  assert(messagehdlrdata != NULL && messagehdlrdata->objmessagehdlr != NULL);
92 
93  /* call virtual method of messagehdlr object */
94  messagehdlrdata->objmessagehdlr->scip_dialog(messagehdlr, file, msg);
95 }
96 
97 
98 /** info message print method of message handler */
99 static
100 SCIP_DECL_MESSAGEINFO(messagehdlrInfoObj)
101 { /*lint --e{715}*/
102  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
103 
104  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
105  assert(messagehdlrdata != NULL && messagehdlrdata->objmessagehdlr != NULL);
106 
107  /* call virtual method of messagehdlr object */
108  messagehdlrdata->objmessagehdlr->scip_info(messagehdlr, file, msg);
109 }
110 
111 /** destructor of message handler to free message handler data */
112 static
114 { /*lint --e{715}*/
115  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
116 
117  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
118  assert(messagehdlrdata != NULL && messagehdlrdata->objmessagehdlr != NULL);
119 
120  /* call virtual method of messagehdlr object */
121  SCIP_CALL( messagehdlrdata->objmessagehdlr->scip_free(messagehdlr) );
122 
123  /* free message handler object */
124  if( messagehdlrdata->deleteobject )
125  delete messagehdlrdata->objmessagehdlr;
126 
127  /* free message handler data */
128  delete messagehdlrdata;
129  SCIP_CALL( SCIPmessagehdlrSetData(messagehdlr, NULL) ); /*lint !e64*/
130 
131  return SCIP_OKAY;
132 }
133 }
134 
135 
136 
137 /*
138  * message handler specific interface methods
139  */
140 
141 /** creates the message handler for the given message handler object */
143  SCIP_MESSAGEHDLR** messagehdlr, /**< pointer to store the message handler */
144  scip::ObjMessagehdlr* objmessagehdlr, /**< message handler object */
145  SCIP_Bool deleteobject /**< should the message handler object be deleted when message handler is freed? */
146  )
147 {
148  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
149  SCIP_RETCODE retcode;
150 
151  /* create file messagehdlr data */
152  messagehdlrdata = new SCIP_MESSAGEHDLRDATA;
153  messagehdlrdata->objmessagehdlr = objmessagehdlr;
154  messagehdlrdata->deleteobject = deleteobject;
155 
156  /* create message handler */
157  retcode = SCIPmessagehdlrCreate(messagehdlr, objmessagehdlr->scip_bufferedoutput_, (const char*)NULL, FALSE,
158  messagehdlrWarningObj, messagehdlrDialogObj, messagehdlrInfoObj,
159  messagehdlrFree, messagehdlrdata); /*lint !e429*/
160 
161  if( retcode != SCIP_OKAY )
162  {
163  /* free message handler object */
164  if( messagehdlrdata->deleteobject )
165  delete messagehdlrdata->objmessagehdlr;
166 
167  delete messagehdlrdata;
168  SCIP_CALL( retcode );
169  }
170 
171  return SCIP_OKAY; /*lint !e429 !e593*/
172 }
173 
174 /** returns the message handler object for the given message handler */
176  SCIP_MESSAGEHDLR* messagehdlr /**< message handler */
177  )
178 {
179  SCIP_MESSAGEHDLRDATA* messagehdlrdata;
180 
181  messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
182  assert(messagehdlrdata != NULL && messagehdlrdata->objmessagehdlr != NULL);
183 
184  return messagehdlrdata->objmessagehdlr;
185 }
186 
187 /** set static error output function to the corresponding function of message handler */
189  SCIP_MESSAGEHDLR* messagehdlr /**< message handler */
190  )
191 {
192  assert( messagehdlr != NULL );
193 
194  SCIPmessageSetErrorPrinting(messagehdlrErrorObj, (void*) SCIPgetObjMessagehdlr(messagehdlr));
195 }
#define NULL
Definition: def.h:267
static SCIP_DECL_MESSAGEWARNING(messagehdlrWarningObj)
struct SCIP_MessagehdlrData SCIP_MESSAGEHDLRDATA
Definition: type_message.h:62
C++ wrapper for message handlers.
SCIP_RETCODE SCIPmessagehdlrCreate(SCIP_MESSAGEHDLR **messagehdlr, SCIP_Bool bufferedoutput, const char *filename, SCIP_Bool quiet, SCIP_DECL_MESSAGEWARNING((*messagewarning)), SCIP_DECL_MESSAGEDIALOG((*messagedialog)), SCIP_DECL_MESSAGEINFO((*messageinfo)), SCIP_DECL_MESSAGEHDLRFREE((*messagehdlrfree)), SCIP_MESSAGEHDLRDATA *messagehdlrdata)
Definition: message.c:295
void SCIPsetStaticErrorPrintingMessagehdlr(SCIP_MESSAGEHDLR *messagehdlr)
#define FALSE
Definition: def.h:94
SCIP_RETCODE SCIPcreateObjMessagehdlr(SCIP_MESSAGEHDLR **messagehdlr, scip::ObjMessagehdlr *objmessagehdlr, SCIP_Bool deleteobject)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
virtual void scip_error(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *msg)
static SCIP_DECL_ERRORPRINTING(messagehdlrErrorObj)
static SCIP_DECL_MESSAGEDIALOG(messagehdlrDialogObj)
static SCIP_DECL_MESSAGEINFO(messagehdlrInfoObj)
#define SCIP_CALL(x)
Definition: def.h:380
static SCIP_RETCODE messagehdlrFree(SCIP_MESSAGEHDLR **messagehdlr)
Definition: message.c:256
scip::ObjMessagehdlr * SCIPgetObjMessagehdlr(SCIP_MESSAGEHDLR *messagehdlr)
#define SCIP_Bool
Definition: def.h:91
C++ wrapper for message handlers.
SCIP_RETCODE SCIPmessagehdlrSetData(SCIP_MESSAGEHDLR *messagehdlr, SCIP_MESSAGEHDLRDATA *messagehdlrdata)
Definition: message.c:377
void SCIPmessageSetErrorPrinting(SCIP_DECL_ERRORPRINTING((*errorPrinting)), void *data)
Definition: message.c:851
const SCIP_Bool scip_bufferedoutput_
static SCIP_DECL_MESSAGEHDLRFREE(messagehdlrFree)
SCIP_MESSAGEHDLRDATA * SCIPmessagehdlrGetData(SCIP_MESSAGEHDLR *messagehdlr)
Definition: message.c:887