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