MMDevice
Loading...
Searching...
No Matches
CameraImageMetadata.h
Go to the documentation of this file.
1
2// PROJECT: Micro-Manager
3// SUBSYSTEM: MMDevice
4//-----------------------------------------------------------------------------
5// COPYRIGHT: 2026, Board of Regents of the University of Wisconsin System
6//
7// LICENSE: This file is distributed under the BSD license.
8// License text is included with the source distribution.
9//
10// This file is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty
12// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13//
14// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
15// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
17
18#pragma once
19
20#include <cassert>
21#include <map>
22#include <sstream>
23#include <string>
24
25namespace MM {
26
28public:
29 // The memory warning in the AddTag() docs below doesn't apply to the
30 // current std::map implementation but will apply to an intended future
31 // implementation that serializes on the fly.
32
55 template <typename V>
56 void AddTag(const char* key, V value) {
57 assert(key != nullptr);
58 std::ostringstream strm;
59 strm << value;
60 tags_[key] = strm.str();
61 }
62
64 void AddTag(const char* key, const char* value) {
65 assert(key != nullptr);
66 assert(value != nullptr);
67 tags_[key] = value;
68 }
69
71 template <typename V>
72 void AddTag(const std::string& key, V value) {
73 // Once we drop C++14 support, we could replace the char* and std::string&
74 // overloads with std::string_view.
75 AddTag(key.c_str(), value);
76 }
77
81 void Clear() { tags_.clear(); }
82
95 const char* Serialize() const {
96 // The serialization format used here is part of the versioned Device
97 // Interface.
98 //
99 // Header: <tag_count>\n
100 // (Spaces are tolerated before and after the tag count.)
101 // For each tag: s\n<name>\n_\n1\n<value>\n
102 // (The 's' indicates "single (not array) tag"; arrays are never used.)
103 // (The '_' device-label field is always "_".)
104 // (The '1' indicates "read-only"; no actual meaning.)
105 //
106 // Tags must have unique keys up to DIV 74. In DIV 75+, the last
107 // occurrence of duplicate tags wins.
108
109 serialized_.clear();
110 serialized_ = std::to_string(tags_.size());
111 serialized_ += '\n';
112 for (const auto& tag : tags_) {
113 serialized_ += "s\n";
114 serialized_ += tag.first;
115 serialized_ += "\n_\n1\n";
116 serialized_ += tag.second;
117 serialized_ += '\n';
118 }
119 return serialized_.c_str();
120 }
121
122private:
123 std::map<std::string, std::string> tags_;
124
125 mutable std::string serialized_; // Valid after Serialize()
126};
127
128} // namespace MM
Definition CameraImageMetadata.h:27
void AddTag(const char *key, const char *value)
Optimized overload for string values.
Definition CameraImageMetadata.h:64
void Clear()
Remove all tags.
Definition CameraImageMetadata.h:81
void AddTag(const char *key, V value)
Add a tag.
Definition CameraImageMetadata.h:56
const char * Serialize() const
Return this metadata map serialized to string form.
Definition CameraImageMetadata.h:95
void AddTag(const std::string &key, V value)
Overload for std::string key.
Definition CameraImageMetadata.h:72
Definition CameraImageMetadata.h:25