File: CbcEventHandler.cpp

package info (click to toggle)
coinor-cbc 2.9.9+repack1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,848 kB
  • ctags: 5,787
  • sloc: cpp: 104,337; sh: 8,921; xml: 2,950; makefile: 520; ansic: 491; awk: 197
file content (126 lines) | stat: -rw-r--r-- 3,699 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* $Id: CbcEventHandler.cpp 1943 2013-07-21 09:05:45Z forrest $ */
// Copyright (C) 2004, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

// Shamelessly adapted from ClpEventHandler.

#include "CoinPragma.hpp"

#include "CbcEventHandler.hpp"


//#############################################################################
// Constructors / Destructor / Assignment
//#############################################################################

//-------------------------------------------------------------------
// Default Constructor
//-------------------------------------------------------------------

CbcEventHandler::CbcEventHandler (CbcModel *model)
        : model_(model),
        dfltAction_(CbcEventHandler::noAction),
        eaMap_(0)
{  /* nothing more required */ }

//-------------------------------------------------------------------
// Copy constructor
//-------------------------------------------------------------------
/*
  Here we need to clone the event/action map, if it exists
*/
CbcEventHandler::CbcEventHandler (const CbcEventHandler & rhs)
        : model_(rhs.model_),
        dfltAction_(rhs.dfltAction_),
        eaMap_(0)
{
    if (rhs.eaMap_ != 0) {
        eaMap_ = new eaMapPair(*rhs.eaMap_) ;
    }
}

//----------------------------------------------------------------
// Assignment operator
//-------------------------------------------------------------------
CbcEventHandler&
CbcEventHandler::operator=(const CbcEventHandler & rhs)
{
    if (this != &rhs) {
        model_ = rhs.model_ ;
        dfltAction_ = rhs.dfltAction_ ;
        if (rhs.eaMap_ != 0) {
            eaMap_ = new eaMapPair(*rhs.eaMap_) ;
        } else {
            eaMap_ = 0 ;
        }
    }
    return (*this) ;
}

//----------------------------------------------------------------
// Clone
//-------------------------------------------------------------------
CbcEventHandler*
CbcEventHandler::clone() const
{
    return (new CbcEventHandler(*this)) ;
}

//-------------------------------------------------------------------
// Destructor
//-------------------------------------------------------------------
/*
  Take care to free the event/action map.
*/
CbcEventHandler::~CbcEventHandler ()
{
    if (eaMap_ != 0) delete eaMap_ ;
}


//-------------------------------------------------------------------
// event() -- return the action for an event.
//-------------------------------------------------------------------

CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event)
/*
  If an event/action map exists and contains an entry for the event, return it.
  Otherwise return the default action.
*/
{
    if (eaMap_ != 0) {
        eaMapPair::iterator entry = eaMap_->find(event) ;
        if (entry != eaMap_->end()) {
            return (entry->second) ;
        } else {
            return (dfltAction_) ;
        }
    } else {
        return (dfltAction_) ;
    }
}

//-------------------------------------------------------------------
// event() -- return the action for an event.
//-------------------------------------------------------------------

CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event,
						  void * /*data*/)
/*
  If an event/action map exists and contains an entry for the event, return it.
  Otherwise return the default action.
*/
{
    if (eaMap_ != 0) {
        eaMapPair::iterator entry = eaMap_->find(event) ;
        if (entry != eaMap_->end()) {
            return (entry->second) ;
        } else {
            return (dfltAction_) ;
        }
    } else {
        return (dfltAction_) ;
    }
}