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