@@ -165,13 +165,46 @@ class RdsObject {
165165 }
166166};
167167
168+ class RdaObject {
169+ private:
170+ std::unique_ptr<rds2cpp::RdaFile> parsed;
171+
172+ public:
173+ RdaObject (const std::string& file) {
174+ try {
175+ rds2cpp::ParseRdaOptions options;
176+ parsed = std::make_unique<rds2cpp::RdaFile>(rds2cpp::parse_rda (file, options));
177+ } catch (const std::exception& e) {
178+ throw std::runtime_error (std::string (" Error in 'RdaObject' constructor: " ) + e.what ());
179+ }
180+ }
181+
182+ py::list get_object_names () const {
183+ if (!parsed) throw std::runtime_error (" Null parsed in 'get_object_names'" );
184+ const auto & pairlist = parsed->contents ;
185+ py::list names;
186+ for (size_t i = 0 ; i < pairlist.tag_names .size (); ++i) {
187+ if (pairlist.has_tag [i]) {
188+ names.append (pairlist.tag_names [i]);
189+ } else {
190+ names.append (py::none ());
191+ }
192+ }
193+ return names;
194+ }
195+ };
196+
168197PYBIND11_MODULE (lib_rds_parser, m) {
169198 py::register_exception<std::runtime_error>(m, " RdsParserError" );
170199
171200 py::class_<RdsObject>(m, " RdsObject" )
172201 .def (py::init<const std::string&>())
173202 .def (" get_robject" , &RdsObject::get_robject, py::return_value_policy::reference_internal);
174203
204+ py::class_<RdaObject>(m, " RdaObject" )
205+ .def (py::init<const std::string&>())
206+ .def (" get_object_names" , &RdaObject::get_object_names);
207+
175208 py::class_<RdsReader>(m, " RdsReader" )
176209 .def (py::init<const rds2cpp::RObject*>())
177210 .def (" get_rtype" , &RdsReader::get_rtype)
0 commit comments