source: trunk/Cbc/src/CbcEventHandler.cpp @ 1514

Last change on this file since 1514 was 1286, checked in by EdwinStraver, 10 years ago

Changed formatting using AStyle -A4 -p

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/* $Id: CbcEventHandler.cpp 1286 2009-11-09 23:33:07Z forrest $ */
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
20CbcEventHandler::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*/
32CbcEventHandler::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//-------------------------------------------------------------------
45CbcEventHandler&
46CbcEventHandler::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//-------------------------------------------------------------------
63CbcEventHandler*
64CbcEventHandler::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*/
75CbcEventHandler::~CbcEventHandler ()
76{
77    if (eaMap_ != 0) delete eaMap_ ;
78}
79
80
81//-------------------------------------------------------------------
82// event() -- return the action for an event.
83//-------------------------------------------------------------------
84
85CbcEventHandler::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
Note: See TracBrowser for help on using the repository browser.