Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
ObjectID.h
1// trax track library
2// AD 2015
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include "IDType.h"
30
31#include <vector>
32#include <unordered_map>
33
34namespace trax{
35
36
37 template<class Base>
38 class ObjectID_Imp : public virtual Base{
39 public:
40 using Base::operator=;
41
42 const std::string& Reference( const std::string& name ) const override{
43 auto iter = m_References.find( name );
44 if( iter == m_References.end() )
45 return m_Empty;
46
47 return iter->second;
48 }
49
50 void Reference( const std::string& name, const std::string& reference ) override{
51 if( reference.empty() )
52 m_References.erase( name );
53 else
54 m_References[name] = reference;
55 }
56
57 const std::vector<char const *>& ReferenceNames( const std::string& namePart ) const override{
58 sm_ReferenceNames.clear();
59 for( const auto& pair : m_References )
60 if( pair.first.find( namePart ) != std::string::npos )
61 sm_ReferenceNames.push_back( pair.first.c_str() );
62 return sm_ReferenceNames;
63 }
64
65 IDType ID() const noexcept override{
66 return m_ID;
67 }
68
69 void ID( IDType id ) noexcept override{
70 m_ID = id;
71 }
72 private:
73 std::unordered_map<std::string, std::string> m_References;
74 static const std::string m_Empty;
75 std::string m_Name;
76 IDType m_ID;
77 static std::vector<char const *> sm_ReferenceNames;
78 };
79
80 template<class Base>
81 std::vector<char const *> ObjectID_Imp<Base>::sm_ReferenceNames;
82
83 template<class Base>
84 const std::string ObjectID_Imp<Base>::m_Empty;
85}
Definition ObjectID.h:38
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
Type used for IDs in the trax library.
Definition IDType.h:43