File: SelectorTmp.cpp

package info (click to toggle)
pymol 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 42,288 kB
  • sloc: cpp: 476,472; python: 76,538; ansic: 29,510; javascript: 6,792; sh: 47; makefile: 24
file content (62 lines) | stat: -rw-r--r-- 1,457 bytes parent folder | download | duplicates (2)
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();
}