Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usModuleEvent.cpp
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CppMicroServices
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 #include "usModuleEvent.h"
23 
24 #include "usModule.h"
25 
26 US_BEGIN_NAMESPACE
27 
28 class ModuleEventData : public SharedData
29 {
30 public:
31 
32  ModuleEventData(ModuleEvent::Type type, Module* module)
33  : type(type), module(module)
34  {
35 
36  }
37 
38  ModuleEventData(const ModuleEventData& other)
39  : SharedData(other), type(other.type), module(other.module)
40  {
41 
42  }
43 
44  const ModuleEvent::Type type;
45  Module* const module;
46 
47 private:
48 
49  // purposely not implemented
50  ModuleEventData& operator=(const ModuleEventData&);
51 };
52 
53 ModuleEvent::ModuleEvent()
54  : d(0)
55 {
56 
57 }
58 
60 {
61 
62 }
63 
64 bool ModuleEvent::IsNull() const
65 {
66  return !d;
67 }
68 
70  : d(new ModuleEventData(type, module))
71 {
72 
73 }
74 
76  : d(other.d)
77 {
78 
79 }
80 
82 {
83  d = other.d;
84  return *this;
85 }
86 
88 {
89  return d->module;
90 }
91 
93 {
94  return d->type;
95 }
96 
97 std::ostream& operator<<(std::ostream& os, ModuleEvent::Type eventType)
98 {
99  switch (eventType)
100  {
101  case ModuleEvent::LOADED: return os << "LOADED";
102  case ModuleEvent::UNLOADED: return os << "UNLOADED";
103  case ModuleEvent::LOADING: return os << "LOADING";
104  case ModuleEvent::UNLOADING: return os << "UNLOADING";
105 
106  default: return os << "Unknown module event type (" << static_cast<int>(eventType) << ")";
107  }
108 }
109 
110 std::ostream& operator<<(std::ostream& os, const ModuleEvent& event)
111 {
112  if (event.IsNull()) return os << "NONE";
113 
114  Module* m = event.GetModule();
115  os << event.GetType() << " #" << m->GetModuleId() << " (" << m->GetLocation() << ")";
116  return os;
117 }
118 
119 US_END_NAMESPACE
bool IsNull() const
Module * GetModule() const
std::string GetLocation() const
Definition: usModule.cpp:216
US_Core_EXPORT std::ostream & operator<<(std::ostream &os, ModuleEvent::Type eventType)
Type GetType() const
ModuleEvent & operator=(const ModuleEvent &other)
long GetModuleId() const
Definition: usModule.cpp:211