1 | /* $Id: CbcEventHandler.cpp 1286 2009-11-09 23:33:07Z tkr $ */ |
---|
2 | // Copyright (C) 2004, International Business Machines |
---|
3 | // Corporation and others. All Rights Reserved. |
---|
4 | |
---|
5 | // Shamelessly adapted from ClpEventHandler. |
---|
6 | |
---|
7 | #include "CoinPragma.hpp" |
---|
8 | |
---|
9 | #include "CbcEventHandler.hpp" |
---|
10 | |
---|
11 | |
---|
12 | //############################################################################# |
---|
13 | // Constructors / Destructor / Assignment |
---|
14 | //############################################################################# |
---|
15 | |
---|
16 | //------------------------------------------------------------------- |
---|
17 | // Default Constructor |
---|
18 | //------------------------------------------------------------------- |
---|
19 | |
---|
20 | CbcEventHandler::CbcEventHandler (CbcModel *model) |
---|
21 | : model_(model), |
---|
22 | dfltAction_(CbcEventHandler::noAction), |
---|
23 | eaMap_(0) |
---|
24 | { /* nothing more required */ } |
---|
25 | |
---|
26 | //------------------------------------------------------------------- |
---|
27 | // Copy constructor |
---|
28 | //------------------------------------------------------------------- |
---|
29 | /* |
---|
30 | Here we need to clone the event/action map, if it exists |
---|
31 | */ |
---|
32 | CbcEventHandler::CbcEventHandler (const CbcEventHandler & rhs) |
---|
33 | : model_(rhs.model_), |
---|
34 | dfltAction_(rhs.dfltAction_), |
---|
35 | eaMap_(0) |
---|
36 | { |
---|
37 | if (rhs.eaMap_ != 0) { |
---|
38 | eaMap_ = new eaMapPair(*rhs.eaMap_) ; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | //---------------------------------------------------------------- |
---|
43 | // Assignment operator |
---|
44 | //------------------------------------------------------------------- |
---|
45 | CbcEventHandler& |
---|
46 | CbcEventHandler::operator=(const CbcEventHandler & rhs) |
---|
47 | { |
---|
48 | if (this != &rhs) { |
---|
49 | model_ = rhs.model_ ; |
---|
50 | dfltAction_ = rhs.dfltAction_ ; |
---|
51 | if (rhs.eaMap_ != 0) { |
---|
52 | eaMap_ = new eaMapPair(*rhs.eaMap_) ; |
---|
53 | } else { |
---|
54 | eaMap_ = 0 ; |
---|
55 | } |
---|
56 | } |
---|
57 | return (*this) ; |
---|
58 | } |
---|
59 | |
---|
60 | //---------------------------------------------------------------- |
---|
61 | // Clone |
---|
62 | //------------------------------------------------------------------- |
---|
63 | CbcEventHandler* |
---|
64 | CbcEventHandler::clone() const |
---|
65 | { |
---|
66 | return (new CbcEventHandler(*this)) ; |
---|
67 | } |
---|
68 | |
---|
69 | //------------------------------------------------------------------- |
---|
70 | // Destructor |
---|
71 | //------------------------------------------------------------------- |
---|
72 | /* |
---|
73 | Take care to free the event/action map. |
---|
74 | */ |
---|
75 | CbcEventHandler::~CbcEventHandler () |
---|
76 | { |
---|
77 | if (eaMap_ != 0) delete eaMap_ ; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | //------------------------------------------------------------------- |
---|
82 | // event() -- return the action for an event. |
---|
83 | //------------------------------------------------------------------- |
---|
84 | |
---|
85 | CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event) |
---|
86 | /* |
---|
87 | If an event/action map exists and contains an entry for the event, return it. |
---|
88 | Otherwise return the default action. |
---|
89 | */ |
---|
90 | { |
---|
91 | if (eaMap_ != 0) { |
---|
92 | eaMapPair::iterator entry = eaMap_->find(event) ; |
---|
93 | if (entry != eaMap_->end()) { |
---|
94 | return (entry->second) ; |
---|
95 | } else { |
---|
96 | return (dfltAction_) ; |
---|
97 | } |
---|
98 | } else { |
---|
99 | return (dfltAction_) ; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|