1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
/*
* RAII for temporary selections
*
* (c) 2020 Schrodinger, Inc.
*/
#include "Selector.h"
#include <utility>
SelectorTmp::SelectorTmp(SelectorTmp&& other)
{
*this = std::move(other);
assert(!other.m_name[0]);
assert(other.m_count == -1);
}
/**
* Factory which propagates errors.
* @param sele Selection expression
* @param empty_is_error If true, then an empty expression is an error,
* otherwise not (but getIndex() returns cSelectionInvalid)
*/
pymol::Result<SelectorTmp> SelectorTmp::make(
PyMOLGlobals* G, const char* sele, bool empty_is_error)
{
if (empty_is_error && !sele[0]) {
return pymol::Error("Empty expression");
}
SelectorTmp self;
self.m_G = G;
auto res = SelectorGetTmpResult(G, sele, self.m_name);
if (res) {
assert(!empty_is_error || self.m_name[0]);
self.m_count = res.result();
return std::move(self);
}
return res.error_move();
}
/**
* Factory which propagates errors.
* @param sele Object name pattern or selection expression
*/
pymol::Result<SelectorTmp2> SelectorTmp2::make(
PyMOLGlobals* G, const char* sele, bool empty_is_error)
{
if (empty_is_error && !sele[0]) {
return pymol::Error("Empty expression");
}
SelectorTmp2 self;
self.m_G = G;
auto res = SelectorGetTmp2Result(G, sele, self.m_name);
if (res) {
assert(!empty_is_error || self.m_name[0]);
self.m_count = res.result();
return std::move(self);
}
return res.error_move();
}
|