PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::core::dicom_dictionary Class Reference

#include <dicom_dictionary.h>

Collaboration diagram for kcenon::pacs::core::dicom_dictionary:
Collaboration graph

Public Member Functions

 dicom_dictionary (const dicom_dictionary &)=delete
 
 dicom_dictionary (dicom_dictionary &&)=delete
 
auto operator= (const dicom_dictionary &) -> dicom_dictionary &=delete
 
auto operator= (dicom_dictionary &&) -> dicom_dictionary &=delete
 
auto find (dicom_tag tag) const -> std::optional< tag_info >
 Find tag metadata by DICOM tag.
 
auto find_by_keyword (std::string_view keyword) const -> std::optional< tag_info >
 Find tag metadata by keyword.
 
auto contains (dicom_tag tag) const -> bool
 Check if a tag exists in the dictionary.
 
auto contains_keyword (std::string_view keyword) const -> bool
 Check if a keyword exists in the dictionary.
 
auto validate_vm (dicom_tag tag, uint32_t count) const -> bool
 Validate that a value count is valid for a tag's VM.
 
auto get_vr (dicom_tag tag) const -> uint16_t
 Get the VR type for a tag.
 
auto register_private_tag (const tag_info &info) -> bool
 Register a private tag at runtime.
 
auto size () const -> size_t
 Get the total number of tags in the dictionary.
 
auto standard_tag_count () const -> size_t
 Get the number of standard (non-private) tags.
 
auto private_tag_count () const -> size_t
 Get the number of registered private tags.
 
auto get_tags_in_group (uint16_t group) const -> std::vector< tag_info >
 Get all tags in a specific group.
 

Static Public Member Functions

static auto instance () -> dicom_dictionary &
 Get the singleton instance.
 

Private Member Functions

 dicom_dictionary ()
 Private constructor - initializes with standard tags.
 
void initialize_standard_tags ()
 Initialize the dictionary with standard PS3.6 tags.
 

Private Attributes

std::unordered_map< dicom_tag, tag_infotag_map_
 Hash map for O(1) lookup by tag.
 
std::unordered_map< std::string_view, dicom_tagkeyword_map_
 Hash map for O(1) lookup by keyword.
 
size_t standard_count_ {0}
 Count of standard tags (vs private)
 
std::shared_mutex mutex_
 Mutex for thread-safe private tag registration.
 

Detailed Description

Examples
dcm_dump/main.cpp.

Definition at line 65 of file dicom_dictionary.h.

Constructor & Destructor Documentation

◆ dicom_dictionary() [1/3]

kcenon::pacs::core::dicom_dictionary::dicom_dictionary ( const dicom_dictionary & )
delete

◆ dicom_dictionary() [2/3]

kcenon::pacs::core::dicom_dictionary::dicom_dictionary ( dicom_dictionary && )
delete

◆ dicom_dictionary() [3/3]

kcenon::pacs::core::dicom_dictionary::dicom_dictionary ( )
private

Private constructor - initializes with standard tags.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 25 of file dicom_dictionary.cpp.

25 {
27}
void initialize_standard_tags()
Initialize the dictionary with standard PS3.6 tags.

References initialize_standard_tags().

Here is the call graph for this function:

Member Function Documentation

◆ contains()

auto kcenon::pacs::core::dicom_dictionary::contains ( dicom_tag tag) const -> bool
nodiscard

Check if a tag exists in the dictionary.

Parameters
tagThe DICOM tag to check
Returns
true if the tag is in the dictionary
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 69 of file dicom_dictionary.cpp.

69 {
70 std::shared_lock lock(mutex_);
71 return tag_map_.contains(tag);
72}
std::shared_mutex mutex_
Mutex for thread-safe private tag registration.
std::unordered_map< dicom_tag, tag_info > tag_map_
Hash map for O(1) lookup by tag.

◆ contains_keyword()

auto kcenon::pacs::core::dicom_dictionary::contains_keyword ( std::string_view keyword) const -> bool
nodiscard

Check if a keyword exists in the dictionary.

Parameters
keywordThe keyword to check
Returns
true if the keyword is in the dictionary
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 74 of file dicom_dictionary.cpp.

74 {
75 std::shared_lock lock(mutex_);
76 return keyword_map_.contains(keyword);
77}
std::unordered_map< std::string_view, dicom_tag > keyword_map_
Hash map for O(1) lookup by keyword.

◆ find()

auto kcenon::pacs::core::dicom_dictionary::find ( dicom_tag tag) const -> std::optional<tag_info>
nodiscard

Find tag metadata by DICOM tag.

Parameters
tagThe DICOM tag to look up
Returns
Optional containing tag_info if found, nullopt otherwise

O(1) average time complexity using hash table lookup. Thread-safe for concurrent reads.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h, and dcm_dump/main.cpp.

Definition at line 45 of file dicom_dictionary.cpp.

45 {
46 std::shared_lock lock(mutex_);
47
48 const auto it = tag_map_.find(tag);
49 if (it != tag_map_.end()) {
50 return it->second;
51 }
52 return std::nullopt;
53}

◆ find_by_keyword()

auto kcenon::pacs::core::dicom_dictionary::find_by_keyword ( std::string_view keyword) const -> std::optional<tag_info>
nodiscard

Find tag metadata by keyword.

Parameters
keywordThe tag keyword (e.g., "PatientName")
Returns
Optional containing tag_info if found, nullopt otherwise

O(1) average time complexity using hash table lookup. Thread-safe for concurrent reads.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 55 of file dicom_dictionary.cpp.

56 {
57 std::shared_lock lock(mutex_);
58
59 const auto it = keyword_map_.find(keyword);
60 if (it != keyword_map_.end()) {
61 const auto tag_it = tag_map_.find(it->second);
62 if (tag_it != tag_map_.end()) {
63 return tag_it->second;
64 }
65 }
66 return std::nullopt;
67}

◆ get_tags_in_group()

auto kcenon::pacs::core::dicom_dictionary::get_tags_in_group ( uint16_t group) const -> std::vector<tag_info>
nodiscard

Get all tags in a specific group.

Parameters
groupThe group number to filter by
Returns
Vector of tag_info for all tags in the group
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 130 of file dicom_dictionary.cpp.

131 {
132 std::shared_lock lock(mutex_);
133
134 std::vector<tag_info> result;
135 for (const auto& [tag, info] : tag_map_) {
136 if (tag.group() == group) {
137 result.push_back(info);
138 }
139 }
140
141 std::sort(result.begin(), result.end(),
142 [](const auto& a, const auto& b) {
143 return a.tag < b.tag;
144 });
145
146 return result;
147}

◆ get_vr()

auto kcenon::pacs::core::dicom_dictionary::get_vr ( dicom_tag tag) const -> uint16_t
nodiscard

Get the VR type for a tag.

Parameters
tagThe DICOM tag
Returns
The VR type as uint16_t, or 0 if tag not found
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 87 of file dicom_dictionary.cpp.

87 {
88 const auto info = find(tag);
89 if (!info) {
90 return 0;
91 }
92 return info->vr;
93}
auto find(dicom_tag tag) const -> std::optional< tag_info >
Find tag metadata by DICOM tag.

◆ initialize_standard_tags()

void kcenon::pacs::core::dicom_dictionary::initialize_standard_tags ( )
private

Initialize the dictionary with standard PS3.6 tags.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 29 of file dicom_dictionary.cpp.

29 {
30 const auto tags = get_standard_tags();
31
32 tag_map_.reserve(tags.size());
33 keyword_map_.reserve(tags.size());
34
35 for (const auto& info : tags) {
36 tag_map_.emplace(info.tag, info);
37 if (!info.keyword.empty()) {
38 keyword_map_.emplace(info.keyword, info.tag);
39 }
40 }
41
42 standard_count_ = tags.size();
43}
size_t standard_count_
Count of standard tags (vs private)
auto get_standard_tags() -> std::span< const tag_info >

References kcenon::pacs::core::get_standard_tags(), keyword_map_, standard_count_, and tag_map_.

Referenced by dicom_dictionary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ instance()

auto kcenon::pacs::core::dicom_dictionary::instance ( ) -> dicom_dictionary&
staticnodiscard

Get the singleton instance.

Returns
Reference to the global dicom_dictionary instance

Thread-safe initialization using C++11 static initialization guarantee.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h, dcm_anonymize/main.cpp, and dcm_modify/main.cpp.

Definition at line 20 of file dicom_dictionary.cpp.

20 {
21 static dicom_dictionary instance;
22 return instance;
23}
static auto instance() -> dicom_dictionary &
Get the singleton instance.

Referenced by kcenon::pacs::encoding::implicit_vr_codec::decode_element(), and kcenon::pacs::core::dicom_file::decode_implicit_vr_le().

Here is the caller graph for this function:

◆ operator=() [1/2]

auto kcenon::pacs::core::dicom_dictionary::operator= ( const dicom_dictionary & ) -> dicom_dictionary &=delete
delete

◆ operator=() [2/2]

auto kcenon::pacs::core::dicom_dictionary::operator= ( dicom_dictionary && ) -> dicom_dictionary &=delete
delete

◆ private_tag_count()

auto kcenon::pacs::core::dicom_dictionary::private_tag_count ( ) const -> size_t
nodiscard

Get the number of registered private tags.

Returns
The count of runtime-registered private tags
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 125 of file dicom_dictionary.cpp.

125 {
126 std::shared_lock lock(mutex_);
127 return tag_map_.size() - standard_count_;
128}

References mutex_, standard_count_, and tag_map_.

◆ register_private_tag()

auto kcenon::pacs::core::dicom_dictionary::register_private_tag ( const tag_info & info) -> bool

Register a private tag at runtime.

Parameters
infoThe tag_info for the private tag
Returns
true if registration succeeded, false if tag already exists

Only private tags (odd group numbers > 0x0008) can be registered. Thread-safe, serializes write operations.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 95 of file dicom_dictionary.cpp.

95 {
96 // Only allow private tags
97 if (!info.tag.is_private()) {
98 return false;
99 }
100
101 std::unique_lock lock(mutex_);
102
103 // Check if already exists
104 if (tag_map_.contains(info.tag)) {
105 return false;
106 }
107
108 tag_map_.emplace(info.tag, info);
109 if (!info.keyword.empty()) {
110 keyword_map_.emplace(info.keyword, info.tag);
111 }
112
113 return true;
114}

◆ size()

auto kcenon::pacs::core::dicom_dictionary::size ( ) const -> size_t
nodiscard

Get the total number of tags in the dictionary.

Returns
The count of registered tags (standard + private)
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 116 of file dicom_dictionary.cpp.

116 {
117 std::shared_lock lock(mutex_);
118 return tag_map_.size();
119}

References mutex_, and tag_map_.

◆ standard_tag_count()

auto kcenon::pacs::core::dicom_dictionary::standard_tag_count ( ) const -> size_t
nodiscard

Get the number of standard (non-private) tags.

Returns
The count of standard PS3.6 tags
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 121 of file dicom_dictionary.cpp.

121 {
122 return standard_count_;
123}

References standard_count_.

◆ validate_vm()

auto kcenon::pacs::core::dicom_dictionary::validate_vm ( dicom_tag tag,
uint32_t count ) const -> bool
nodiscard

Validate that a value count is valid for a tag's VM.

Parameters
tagThe DICOM tag to validate against
countThe number of values to validate
Returns
true if count satisfies the tag's VM, false if tag not found or invalid
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 79 of file dicom_dictionary.cpp.

79 {
80 const auto info = find(tag);
81 if (!info) {
82 return false;
83 }
84 return info->vm.is_valid(count);
85}

Member Data Documentation

◆ keyword_map_

std::unordered_map<std::string_view, dicom_tag> kcenon::pacs::core::dicom_dictionary::keyword_map_
private

Hash map for O(1) lookup by keyword.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 182 of file dicom_dictionary.h.

Referenced by initialize_standard_tags().

◆ mutex_

std::shared_mutex kcenon::pacs::core::dicom_dictionary::mutex_
mutableprivate

Mutex for thread-safe private tag registration.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/dicom_dictionary.h.

Definition at line 188 of file dicom_dictionary.h.

Referenced by private_tag_count(), and size().

◆ standard_count_

size_t kcenon::pacs::core::dicom_dictionary::standard_count_ {0}
private

◆ tag_map_

std::unordered_map<dicom_tag, tag_info> kcenon::pacs::core::dicom_dictionary::tag_map_
private

The documentation for this class was generated from the following files: