Commit 86854581 by Maarten L. Hekkelman

Add contructor loading raw data to mmcif::File

parent ef819448
...@@ -390,6 +390,7 @@ class File : public std::enable_shared_from_this<File> ...@@ -390,6 +390,7 @@ class File : public std::enable_shared_from_this<File>
public: public:
File(); File();
File(const std::string& path); File(const std::string& path);
File(const char* data, size_t length); // good luck trying to find out what it is...
~File(); ~File();
File(const File&) = delete; File(const File&) = delete;
......
...@@ -60,10 +60,48 @@ struct FileImpl ...@@ -60,10 +60,48 @@ struct FileImpl
cif::File mData; cif::File mData;
cif::Datablock* mDb = nullptr; cif::Datablock* mDb = nullptr;
void load_data(const char* data, size_t length);
void load(const std::string& p); void load(const std::string& p);
void save(const std::string& p); void save(const std::string& p);
}; };
void FileImpl::load_data(const char* data, size_t length)
{
try
{
// First try mmCIF
struct membuf : public std::streambuf
{
membuf(char* data, size_t length) { this->setg(data, data, data + length); }
} buffer(const_cast<char*>(data), length);
std::istream is(&buffer);
mData.load(is);
}
catch (const cif::CifParserError& e)
{
// First try mmCIF
struct membuf : public std::streambuf
{
membuf(char* data, size_t length) { this->setg(data, data, data + length); }
} buffer(const_cast<char*>(data), length);
std::istream is(&buffer);
ReadPDBFile(is, mData);
}
// Yes, we've parsed the data. Now locate the datablock.
mDb = &mData.firstDatablock();
// And validate, otherwise lots of functionality won't work
// if (mData.getValidator() == nullptr)
mData.loadDictionary("mmcif_pdbx_v50");
if (not mData.isValid())
std::cerr << "Invalid mmCIF file" << (cif::VERBOSE ? "." : " use --verbose option to see errors") << std::endl;
}
void FileImpl::load(const std::string& p) void FileImpl::load(const std::string& p)
{ {
fs::path path(p); fs::path path(p);
...@@ -1628,6 +1666,12 @@ File::File() ...@@ -1628,6 +1666,12 @@ File::File()
{ {
} }
File::File(const char* data, size_t length)
: mImpl(new FileImpl)
{
mImpl->load_data(data, length);
}
File::File(const std::string& File) File::File(const std::string& File)
: mImpl(new FileImpl) : mImpl(new FileImpl)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment