@@ -68,7 +68,8 @@ void getGroup(H5::Group groupID, std::map<std::string, std::set<std::string>> &a
68
68
} // namespace
69
69
70
70
NexusDescriptor::NexusDescriptor (std::string filename)
71
- : m_filename(std::move(filename)), m_extension(), m_firstEntryNameType(), m_allEntries(initAllEntries()) {}
71
+ : m_filename(std::move(filename)), m_extension(std::filesystem::path(m_filename).extension().string()),
72
+ m_firstEntryNameType (), m_allEntries(initAllEntries()) {}
72
73
73
74
// PUBLIC
74
75
const std::string &NexusDescriptor::filename () const noexcept { return m_filename; }
@@ -78,10 +79,31 @@ bool NexusDescriptor::hasRootAttr(const std::string &name) const { return (m_roo
78
79
const std::map<std::string, std::set<std::string>> &NexusDescriptor::getAllEntries () const noexcept {
79
80
return m_allEntries;
80
81
}
82
+ void NexusDescriptor::addEntry (const std::string &entryName, const std::string &groupClass) {
83
+ // simple checks
84
+ if (entryName.empty ())
85
+ throw std::runtime_error (" Cannot add empty path" );
86
+ if (groupClass.empty ())
87
+ throw std::runtime_error (" Cannot add empty class" );
88
+ if (entryName.find (" /" ) != 0 )
89
+ throw std::runtime_error (" Paths must be absolute: " + entryName);
90
+
91
+ // do not add path twice
92
+ if (this ->isEntry (entryName))
93
+ throw std::runtime_error (" Cannot add an entry twice: " + entryName);
94
+
95
+ // verify the parent exists
96
+ const auto lastPos = entryName.rfind (" /" );
97
+ const auto parentPath = entryName.substr (0 , lastPos);
98
+ if (!this ->isEntry (parentPath))
99
+ throw std::runtime_error (" Parent path " + parentPath + " does not exist" );
100
+
101
+ // add the path
102
+ m_allEntries[groupClass].insert (entryName);
103
+ }
81
104
82
105
// PRIVATE
83
106
std::map<std::string, std::set<std::string>> NexusDescriptor::initAllEntries () {
84
- m_extension = std::filesystem::path (m_filename).extension ().string ();
85
107
H5::FileAccPropList access_plist;
86
108
access_plist.setFcloseDegree (H5F_CLOSE_STRONG);
87
109
0 commit comments