source: trunk/Cbc/src/CbcEventHandler.cpp

Last change on this file was 2465, checked in by unxusr, 9 months ago

script to format sources

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: CbcEventHandler.cpp 2465 2019-01-03 19:26:52Z stefan $ */
2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6// Shamelessly adapted from ClpEventHandler.
7
8#include "CoinPragma.hpp"
9
10#include "CbcEventHandler.hpp"
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//-------------------------------------------------------------------
28// Copy constructor
29//-------------------------------------------------------------------
30/*
31  Here we need to clone the event/action map, if it exists
32*/
33CbcEventHandler::CbcEventHandler(const CbcEventHandler &rhs)
34  : model_(rhs.model_)
35  , dfltAction_(rhs.dfltAction_)
36  , eaMap_(0)
37{
38  if (rhs.eaMap_ != 0) {
39    eaMap_ = new eaMapPair(*rhs.eaMap_);
40  }
41}
42
43//----------------------------------------------------------------
44// Assignment operator
45//-------------------------------------------------------------------
46CbcEventHandler &
47CbcEventHandler::operator=(const CbcEventHandler &rhs)
48{
49  if (this != &rhs) {
50    model_ = rhs.model_;
51    dfltAction_ = rhs.dfltAction_;
52    if (rhs.eaMap_ != 0) {
53      eaMap_ = new eaMapPair(*rhs.eaMap_);
54    } else {
55      eaMap_ = 0;
56    }
57  }
58  return (*this);
59}
60
61//----------------------------------------------------------------
62// Clone
63//-------------------------------------------------------------------
64CbcEventHandler *
65CbcEventHandler::clone() const
66{
67  return (new CbcEventHandler(*this));
68}
69
70//-------------------------------------------------------------------
71// Destructor
72//-------------------------------------------------------------------
73/*
74  Take care to free the event/action map.
75*/
76CbcEventHandler::~CbcEventHandler()
77{
78  if (eaMap_ != 0)
79    delete eaMap_;
80}
81
82//-------------------------------------------------------------------
83// event() -- return the action for an event.
84//-------------------------------------------------------------------
85
86CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event)
87/*
88  If an event/action map exists and contains an entry for the event, return it.
89  Otherwise return the default action.
90*/
91{
92  if (eaMap_ != 0) {
93    eaMapPair::iterator entry = eaMap_->find(event);
94    if (entry != eaMap_->end()) {
95      return (entry->second);
96    } else {
97      return (dfltAction_);
98    }
99  } else {
100    return (dfltAction_);
101  }
102}
103
104//-------------------------------------------------------------------
105// event() -- return the action for an event.
106//-------------------------------------------------------------------
107
108CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event,
109  void * /*data*/)
110/*
111  If an event/action map exists and contains an entry for the event, return it.
112  Otherwise return the default action.
113*/
114{
115  if (eaMap_ != 0) {
116    eaMapPair::iterator entry = eaMap_->find(event);
117    if (entry != eaMap_->end()) {
118      return (entry->second);
119    } else {
120      return (dfltAction_);
121    }
122  } else {
123    return (dfltAction_);
124  }
125}
126
127/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
128*/
Note: See TracBrowser for help on using the repository browser.