Scippy

SCIP

Solving Constraint Integer Programs

objreader.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-2017 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 objreader.h
17  * @brief C++ wrapper for file readers and writers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #ifndef __SCIP_OBJREADER_H__
24 #define __SCIP_OBJREADER_H__
25 
26 #include <cstring>
27 
28 #include "scip/scip.h"
29 #include "objscip/objcloneable.h"
30 
31 namespace scip
32 {
33 
34 /** @brief C++ wrapper for file readers and writers
35  *
36  * This class defines the interface for file readers and writers implemented in C++.
37  *
38  * - \ref READER "Instructions for implementing a file reader and writer"
39  * - \ref FILEREADERS "List of available file readers and writers"
40  * - \ref type_reader.h "Corresponding C interface"
41  */
42 class ObjReader : public ObjCloneable
43 {
44 public:
45  /*lint --e{1540}*/
46 
47  /** SCIP data structure */
49 
50  /** name of the file reader */
51  char* scip_name_;
52 
53  /** description of the file reader */
54  char* scip_desc_;
55 
56  /** file extension that reader processes */
58 
59  /** default constructor */
61  SCIP* scip, /**< SCIP data structure */
62  const char* name, /**< name of file reader */
63  const char* desc, /**< description of file reader */
64  const char* extension /**< file extension that reader processes */
65  )
66  : scip_(scip),
67  scip_name_(0),
68  scip_desc_(0),
69  scip_extension_(0)
70  {
71  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
72  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
73  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
74  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_extension_, extension, std::strlen(extension)+1) );
75  }
76 
77  /** destructor */
78  virtual ~ObjReader()
79  {
80  /* the macro SCIPfreeMemoryArray does not need the first argument: */
81  /*lint --e{64}*/
82  SCIPfreeMemoryArray(scip_, &scip_name_);
83  SCIPfreeMemoryArray(scip_, &scip_desc_);
84  SCIPfreeMemoryArray(scip_, &scip_extension_);
85  }
86 
87  /** destructor of file reader to free user data (called when SCIP is exiting)
88  *
89  * @see SCIP_DECL_READERFREE(x) in @ref type_reader.h
90  */
91  virtual SCIP_DECL_READERFREE(scip_free)
92  { /*lint --e{715}*/
93  return SCIP_OKAY;
94  }
95 
96  /** problem reading method of reader
97  *
98  * @see SCIP_DECL_READERREAD(x) in @ref type_reader.h
99  */
100  virtual SCIP_DECL_READERREAD(scip_read)
101  { /*lint --e{715}*/
102 
103  /* set result pointer to indicate that the reading was not performed */
104  assert(result != NULL);
105  (*result) = SCIP_DIDNOTRUN;
106 
107  return SCIP_OKAY;
108  }
109 
110  /** problem writing method of reader; NOTE: if the parameter "genericnames" is TRUE, then
111  * SCIP already set all variable and constraint names to generic names; therefore, this
112  * method should always use SCIPvarGetName() and SCIPconsGetName();
113  *
114  * @see SCIP_DECL_READERWRITE(x) in @ref type_reader.h
115  */
116  virtual SCIP_DECL_READERWRITE(scip_write)
117  { /*lint --e{715}*/
118 
119  /* set result pointer to indicate that the writing was not performed */
120  assert(result != NULL);
121  (*result) = SCIP_DIDNOTRUN;
122 
123  return SCIP_OKAY;
124  }
125 };
126 
127 } /* namespace scip */
128 
129 
130 
131 /** creates the file reader for the given file reader object and includes it in SCIP
132  *
133  * The method should be called in one of the following ways:
134  *
135  * 1. The user is resposible of deleting the object:
136  * SCIP_CALL( SCIPcreate(&scip) );
137  * ...
138  * MyReader* myreader = new MyReader(...);
139  * SCIP_CALL( SCIPincludeObjReader(scip, &myreader, FALSE) );
140  * ...
141  * SCIP_CALL( SCIPfree(&scip) );
142  * delete myreader; // delete reader AFTER SCIPfree() !
143  *
144  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
145  * SCIP_CALL( SCIPcreate(&scip) );
146  * ...
147  * SCIP_CALL( SCIPincludeObjReader(scip, new MyReader(...), TRUE) );
148  * ...
149  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyReader is called here
150  */
151 extern
153  SCIP* scip, /**< SCIP data structure */
154  scip::ObjReader* objreader, /**< file reader object */
155  SCIP_Bool deleteobject /**< should the reader object be deleted when reader is freed? */
156  );
157 
158 /** returns the reader object of the given name, or 0 if not existing */
159 extern
161  SCIP* scip, /**< SCIP data structure */
162  const char* name /**< name of file reader */
163  );
164 
165 /** returns the reader object for the given file reader */
166 extern
168  SCIP* scip, /**< SCIP data structure */
169  SCIP_READER* reader /**< file reader */
170  );
171 
172 #endif
SCIP_RETCODE SCIPincludeObjReader(SCIP *scip, scip::ObjReader *objreader, SCIP_Bool deleteobject)
Definition: objreader.cpp:146
SCIP * scip_
Definition: objreader.h:48
char * scip_desc_
Definition: objreader.h:54
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
char * scip_name_
Definition: objreader.h:51
definition of base class for all clonable classes
virtual SCIP_DECL_READERWRITE(scip_write)
Definition: objreader.h:116
ObjReader(SCIP *scip, const char *name, const char *desc, const char *extension)
Definition: objreader.h:60
#define NULL
Definition: lpi_spx1.cpp:137
virtual ~ObjReader()
Definition: objreader.h:78
#define SCIP_Bool
Definition: def.h:61
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip.h:21870
scip::ObjReader * SCIPgetObjReader(SCIP *scip, SCIP_READER *reader)
Definition: objreader.cpp:190
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:21874
char * scip_extension_
Definition: objreader.h:57
scip::ObjReader * SCIPfindObjReader(SCIP *scip, const char *name)
Definition: objreader.cpp:171
C++ wrapper for file readers and writers.
Definition: objreader.h:42
Definition of base class for all clonable classes.
Definition: objcloneable.h:38
virtual SCIP_DECL_READERFREE(scip_free)
Definition: objreader.h:91
virtual SCIP_DECL_READERREAD(scip_read)
Definition: objreader.h:100
#define SCIP_CALL_ABORT(x)
Definition: def.h:285
SCIP callable library.