-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoreProperty.cpp
More file actions
120 lines (102 loc) · 3.94 KB
/
CoreProperty.cpp
File metadata and controls
120 lines (102 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
///////////////////////////////////////////////////////////////////////////////
// FILE: CoreProperty.cpp
// PROJECT: Micro-Manager
// SUBSYSTEM: MMCore
//-----------------------------------------------------------------------------
// DESCRIPTION: Implements the "core property" mechanism. The MMCore exposes
// some of its own settings as a virtual device.
//
// AUTHOR: Nenad Amodaj, nenad@amodaj.com, 10/23/2005
//
// COPYRIGHT: University of California, San Francisco, 2006
//
// LICENSE: This file is distributed under the "Lesser GPL" (LGPL) license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
#include "CoreProperty.h"
#include "CoreUtils.h"
#include "MMCore.h"
#include "Error.h"
#include "Notification.h"
#include <algorithm>
namespace mmcore {
namespace internal {
const CorePropertyDef& CorePropertyCollection::FindOrThrow(const char* propName) const
{
auto it = properties_.find(propName);
if (it == properties_.end())
throw CMMError("Invalid Core property (" + ToString(propName) + ")",
MMERR_InvalidCoreProperty);
return it->second;
}
std::string CorePropertyCollection::Get(const char* propName) const
{
return FindOrThrow(propName).getter();
}
void CorePropertyCollection::Set(const char* propName, const std::string& value)
{
const auto& def = FindOrThrow(propName);
if (def.readOnly)
throw CMMError("Cannot set Core property " + ToString(propName) +
" to value \"" + value + "\" (read-only)",
MMERR_InvalidCoreValue);
if (def.allowedValues) {
auto allowed = def.allowedValues();
if (!allowed.empty()) {
if (std::find(allowed.begin(), allowed.end(), value) == allowed.end())
throw CMMError("Cannot set Core property " + ToString(propName) +
" to invalid value \"" + value + "\"",
MMERR_InvalidCoreValue);
}
}
def.setter(value);
core_->postNotification(
notification::PropertyChanged{"Core", propName, def.getter()});
}
bool CorePropertyCollection::Has(const char* propName) const
{
return properties_.find(propName) != properties_.end();
}
std::vector<std::string> CorePropertyCollection::GetNames() const
{
std::vector<std::string> names;
names.reserve(properties_.size());
for (const auto& kv : properties_)
names.push_back(kv.first);
return names;
}
bool CorePropertyCollection::IsReadOnly(const char* propName) const
{
return FindOrThrow(propName).readOnly;
}
MM::PropertyType CorePropertyCollection::GetPropertyType(const char* propName) const
{
return FindOrThrow(propName).type;
}
std::vector<std::string> CorePropertyCollection::GetAllowedValues(const char* propName) const
{
const auto& def = FindOrThrow(propName);
if (def.allowedValues)
return def.allowedValues();
return {};
}
void CorePropertyCollection::Add(const char* name, CorePropertyDef def)
{
properties_[name] = std::move(def);
}
bool CorePropertyCollection::IsPropertyPreInit(const char*) const { return false; }
bool CorePropertyCollection::HasPropertyLimits(const char*) const { return false; }
double CorePropertyCollection::GetPropertyLowerLimit(const char*) const { return 0.0; }
double CorePropertyCollection::GetPropertyUpperLimit(const char*) const { return 0.0; }
bool CorePropertyCollection::IsPropertySequenceable(const char*) const { return false; }
long CorePropertyCollection::GetPropertySequenceMaxLength(const char*) const { return 0; }
} // namespace internal
} // namespace mmcore