Scippy

SCIP

Solving Constraint Integer Programs

objdialog.h
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 objdialog.h
26  * @brief C++ wrapper for dialogs
27  * @author Kati Wolter
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #ifndef __SCIP_OBJDIALOG_H__
33 #define __SCIP_OBJDIALOG_H__
34 
35 #include <cstring>
36 #include <utility>
37 
38 #include "scip/scip.h"
39 #include "objscip/objcloneable.h"
40 
41 namespace scip
42 {
43 
44 /** @brief C++ wrapper for dialogs
45  *
46  * This class defines the interface for dialogs implemented in C++. Note that there is a pure virtual function (this
47  * function has to be implemented). This function is: scip_exec().
48  *
49  * - \ref DIALOG "Instructions for implementing a dialog"
50  * - \ref DIALOGS "List of available dialogs"
51  * - \ref type_dialog.h "Corresponding C interface"
52  */
53 class ObjDialog : public ObjCloneable
54 {
55 public:
56  /*lint --e{1540}*/
57 
58  /** SCIP data structure */
60 
61  /** name of the dialog */
62  char* scip_name_;
63 
64  /** description of the dialog */
65  char* scip_desc_;
66 
67  /** default for whether the dialog is a menu */
69 
70  /** default constructor */
72  SCIP* scip, /**< SCIP data structure */
73  const char* name, /**< name of the dialog */
74  const char* desc, /**< description of the dialog */
75  SCIP_Bool issubmenu /**< default for whether the dialog is a menu */
76  )
77  : scip_(scip),
78  scip_name_(0),
79  scip_desc_(0),
80  scip_issubmenu_(issubmenu)
81  {
82  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
83  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
84  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
85  }
86 
87  /** copy constructor */
88  ObjDialog(const ObjDialog& o) : ObjDialog(o.scip_, o.scip_name_, o.scip_desc_, o.scip_issubmenu_) {}
89 
90  /** move constructor */
91  ObjDialog(ObjDialog&& o) : scip_(o.scip_), scip_name_(0), scip_desc_(0), scip_issubmenu_(o.scip_issubmenu_)
92  {
93  std::swap(scip_name_, o.scip_name_);
94  std::swap(scip_desc_, o.scip_desc_);
95  }
96 
97  /** destructor */
98  virtual ~ObjDialog()
99  {
100  /* the macro SCIPfreeMemoryArray does not need the first argument: */
101  /*lint --e{64}*/
102  SCIPfreeMemoryArray(scip_, &scip_name_);
103  SCIPfreeMemoryArray(scip_, &scip_desc_);
104  }
105 
106  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
107  ObjDialog& operator=(const ObjDialog& o) = delete;
108 
109  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
110  ObjDialog& operator=(ObjDialog&& o) = delete;
111 
112  /** destructor of dialog to free user data (called when SCIP is exiting)
113  *
114  * @see SCIP_DECL_DIALOGFREE(x) in @ref type_dialog.h
115  */
116  virtual SCIP_DECL_DIALOGFREE(scip_free)
117  { /*lint --e{715}*/
118  return SCIP_OKAY;
119  }
120 
121  /** description output method of dialog
122  *
123  * @see SCIP_DECL_DIALOGDESC(x) in @ref type_dialog.h
124  */
125  virtual SCIP_DECL_DIALOGDESC(scip_desc)
126  { /*lint --e{715}*/
127  SCIPdialogMessage(scip, 0, "%s", scip_desc_);
128  return SCIP_OKAY;
129  }
130 
131  /** execution method of dialog
132  *
133  * @see SCIP_DECL_DIALOGEXEC(x) in @ref type_dialog.h
134  */
135  virtual SCIP_DECL_DIALOGEXEC(scip_exec) = 0;
136 };
137 
138 } /* namespace scip */
139 
140 
141 
142 /** creates the dialog for the given dialog object and includes it in SCIP
143  *
144  * The method should be called in one of the following ways:
145  *
146  * 1. The user is resposible of deleting the object:
147  * SCIP_CALL( SCIPcreate(&scip) );
148  * ...
149  * MyDialog* mydialog = new MyDialog(...);
150  * SCIP_CALL( SCIPincludeObjDialog(scip, &mydialog, FALSE) );
151  * ...
152  * SCIP_CALL( SCIPfree(&scip) );
153  * delete mydialog; // delete dialog AFTER SCIPfree() !
154  *
155  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
156  * SCIP_CALL( SCIPcreate(&scip) );
157  * ...
158  * SCIP_CALL( SCIPincludeObjDialog(scip, new MyDialog(...), TRUE) );
159  * ...
160  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyDialog is called here
161  */
162 SCIP_EXPORT
164  SCIP* scip, /**< SCIP data structure */
165  scip::ObjDialog* objdialog, /**< dialog object */
166  SCIP_Bool deleteobject /**< should the dialog object be deleted when dialog is freed? */
167  );
168 
169 #endif
ObjDialog(const ObjDialog &o)
Definition: objdialog.h:88
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:191
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
C++ wrapper for dialogs.
Definition: objdialog.h:53
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
const SCIP_Bool scip_issubmenu_
Definition: objdialog.h:68
definition of base class for all clonable classes
SCIP * scip_
Definition: objdialog.h:59
ObjDialog(ObjDialog &&o)
Definition: objdialog.h:91
char * scip_name_
Definition: objdialog.h:62
virtual SCIP_DECL_DIALOGFREE(scip_free)
Definition: objdialog.h:116
char * scip_desc_
Definition: objdialog.h:65
virtual SCIP_DECL_DIALOGEXEC(scip_exec)=0
SCIP_RETCODE SCIPincludeObjDialog(SCIP *scip, scip::ObjDialog *objdialog, SCIP_Bool deleteobject)
Definition: objdialog.cpp:152
#define SCIP_Bool
Definition: def.h:91
Definition of base class for all clonable classes.
Definition: objcloneable.h:47
virtual ~ObjDialog()
Definition: objdialog.h:98
ObjDialog(SCIP *scip, const char *name, const char *desc, SCIP_Bool issubmenu)
Definition: objdialog.h:71
#define SCIP_CALL_ABORT(x)
Definition: def.h:359
ObjDialog & operator=(const ObjDialog &o)=delete
virtual SCIP_DECL_DIALOGDESC(scip_desc)
Definition: objdialog.h:125
SCIP callable library.