source: branches/sandbox/Cbc/src/CbcEventHandler.cpp @ 1273

Last change on this file since 1273 was 1271, checked in by forrest, 10 years ago

Creating new stable branch 2.4 from trunk (rev 1270)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/* $Id: CbcEventHandler.cpp 1271 2009-11-05 15:57:25Z 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
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{ if (rhs.eaMap_ != 0)
37  { eaMap_ = new eaMapPair(*rhs.eaMap_) ; } }
38
39//----------------------------------------------------------------
40// Assignment operator
41//-------------------------------------------------------------------
42CbcEventHandler&
43CbcEventHandler::operator=(const CbcEventHandler& rhs)
44{
45  if (this != &rhs) {
46    model_ = rhs.model_ ;
47    dfltAction_ = rhs.dfltAction_ ;
48    if (rhs.eaMap_ != 0)
49    { eaMap_ = new eaMapPair(*rhs.eaMap_) ; }
50    else
51    { eaMap_ = 0 ; } }
52  return (*this) ; }
53
54//----------------------------------------------------------------
55// Clone
56//-------------------------------------------------------------------
57CbcEventHandler* 
58CbcEventHandler::clone() const
59{ return (new CbcEventHandler(*this)) ; }
60
61//-------------------------------------------------------------------
62// Destructor
63//-------------------------------------------------------------------
64/*
65  Take care to free the event/action map.
66*/
67CbcEventHandler::~CbcEventHandler ()
68{ if (eaMap_ != 0) delete eaMap_ ; }
69
70
71//-------------------------------------------------------------------
72// event() -- return the action for an event.
73//-------------------------------------------------------------------
74
75CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event)
76/*
77  If an event/action map exists and contains an entry for the event, return it.
78  Otherwise return the default action.
79*/
80{ if (eaMap_ != 0)
81  { eaMapPair::iterator entry = eaMap_->find(event) ;
82    if (entry != eaMap_->end())
83    { return (entry->second) ; }
84    else
85    { return (dfltAction_) ; } }
86  else
87  { return (dfltAction_) ; } }
88
Note: See TracBrowser for help on using the repository browser.