normativeTypesCPP 6.0.2
ntid.cpp
Go to the documentation of this file.
1/* ntid.cpp */
2/*
3 * Copyright information and license terms for this software can be
4 * found in the file LICENSE that is included with the distribution
5 */
6
7#include <pv/ntid.h>
8#include <pv/typeCast.h>
9
10namespace epics {
11
12namespace nt {
13
14 const static std::string BAD_NAME = "?";
15
16 NTID::NTID(const std::string & id)
17 : fullName(id),
18 qualifiedName(BAD_NAME),
19 namespaceStr(BAD_NAME),
20 name(BAD_NAME),
21 version(BAD_NAME),
22 nsSepIndex(std::string::npos),
23 versionSepIndex(std::string::npos),
24 nsQualified(false),
25 hasVersion(false),
26 endMajorIndex(0),
27 majorVersionStr(BAD_NAME),
28 majorVersionParsed(false),
29 hasMajor(false),
30 majorVersion(0),
31
32 endMinorIndex(0),
33 minorVersionStr(BAD_NAME),
34 minorVersionParsed(false),
35 hasMinor(false),
36 minorVersion(0)
37 {
38 nsSepIndex = id.find('/');
39 nsQualified = nsSepIndex != std::string::npos;
40 size_t startIndex = nsQualified ? nsSepIndex+1 : 0;
41 versionSepIndex = id.find(':', startIndex);
42 hasVersion = versionSepIndex != std::string::npos;
43 }
44
45 std::string NTID::getFullName() { return fullName; }
46
48 {
49 if (qualifiedName == BAD_NAME)
50 {
51 qualifiedName = hasVersion ?
52 fullName.substr(0, versionSepIndex) : fullName;
53 }
54 return qualifiedName;
55 }
56
57
58 std::string NTID::getNamespace()
59 {
60 if (namespaceStr == BAD_NAME)
61 {
62 namespaceStr = nsQualified ?
63 fullName.substr(0, nsSepIndex) : "";
64 }
65 return namespaceStr;
66 }
67
68 std::string NTID::getName()
69 {
70 if (name == BAD_NAME)
71 {
72 if (hasVersion)
73 {
74 size_t startIndex = nsQualified ? nsSepIndex+1 : 0;
75 name = fullName.substr(startIndex, versionSepIndex);
76 }
77 else if (nsQualified)
78 {
79 name = fullName.substr(nsSepIndex+1);
80 }
81 else
82 {
83 name = fullName;
84 }
85 }
86 return name;
87 }
88
89
90 std::string NTID::getVersion()
91 {
92 if (version == BAD_NAME)
93 {
94 version = (hasVersion) ? fullName.substr(versionSepIndex+1) : "";
95 }
96 return version;
97 }
98
99
101 {
102 if (majorVersionStr == BAD_NAME)
103 {
104 if (hasVersion)
105 {
106 endMajorIndex = fullName.find('.', versionSepIndex+1);
107 majorVersionStr = (endMajorIndex != std::string::npos)
108 ? fullName.substr(versionSepIndex+1, endMajorIndex-(versionSepIndex+1)) :
109 fullName.substr(versionSepIndex+1);
110 }
111 else
112 majorVersionStr = "";
113 }
114 return majorVersionStr;
115 }
116
117
119 {
120 if (hasVersion && !majorVersionParsed)
121 {
122 try {
123 using pvData::detail::parseToPOD;
124 uint32_t mv;
125 parseToPOD(getMajorVersionString(), &mv);
126 majorVersion = static_cast<int>(mv);
127 hasMajor = true;
128 } catch (...) {}
129 majorVersionParsed = true;
130 }
131 return hasMajor;
132 }
133
134
136 {
137 // call hasMajorVersion() to calculate values
139 return majorVersion;
140 }
141
142
144 {
145 // call hasMinorVersion() to calculate start of minor
147 if (minorVersionStr == BAD_NAME)
148 {
149 if (hasVersion && endMajorIndex != std::string::npos)
150 {
151 endMinorIndex = fullName.find('.', endMajorIndex+1);
152 minorVersionStr = (endMinorIndex != std::string::npos)
153 ? fullName.substr(endMajorIndex+1, endMinorIndex-(endMajorIndex+1)) :
154 fullName.substr(endMajorIndex+1);
155 }
156 else
157 minorVersionStr = "";
158 }
159 return minorVersionStr;
160 }
161
162
164 {
165 if (hasVersion && !minorVersionParsed)
166 {
167 try {
168 using pvData::detail::parseToPOD;
169 uint32_t mv;
170 parseToPOD(getMinorVersionString(), &mv);
171 minorVersion = static_cast<int>(mv);
172 hasMinor = true;
173 } catch (...) {}
174 minorVersionParsed = true;
175 }
176 return hasMinor;
177 }
178
179
181 {
182 // call hasMinorVersion() to calculate values
184 return minorVersion;
185 }
186
187
188}}
int getMinorVersion()
Definition ntid.cpp:180
NTID(const std::string &id)
Definition ntid.cpp:16
bool hasMinorVersion()
Definition ntid.cpp:163
std::string getNamespace()
Definition ntid.cpp:58
std::string getName()
Definition ntid.cpp:68
std::string getVersion()
Definition ntid.cpp:90
std::string getFullName()
Definition ntid.cpp:45
int getMajorVersion()
Definition ntid.cpp:135
bool hasMajorVersion()
Definition ntid.cpp:118
std::string getMajorVersionString()
Definition ntid.cpp:100
std::string getMinorVersionString()
Definition ntid.cpp:143
std::string getQualifiedName()
Definition ntid.cpp:47