Xmipp  v3.23.11-Nereus
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
cif::TLSSelectionParserImplBuster Class Reference
Inheritance diagram for cif::TLSSelectionParserImplBuster:
Inheritance graph
[legend]
Collaboration diagram for cif::TLSSelectionParserImplBuster:
Collaboration graph
[legend]

Public Member Functions

 TLSSelectionParserImplBuster (const std::string &selection)
 
virtual std::unique_ptr< tls_selection > Parse ()
 
- Public Member Functions inherited from cif::tls_selection_parser_impl
 tls_selection_parser_impl (const std::string &selection)
 

Protected Types

enum  TOKEN { bt_NONE = 0, bt_IDENT = 256, bt_NUMBER, bt_EOLN }
 

Protected Member Functions

virtual int get_next_token ()
 
virtual std::string to_string (int token)
 
std::unique_ptr< tls_selection > ParseGroup ()
 
std::tuple< std::string, int > ParseAtom ()
 
std::unique_ptr< tls_selection > ParseOldGroup ()
 
- Protected Member Functions inherited from cif::tls_selection_parser_impl
virtual void match (int token)
 

Protected Attributes

int m_value_i
 
std::string m_value_s
 
bool m_parsing_old_style = false
 
- Protected Attributes inherited from cif::tls_selection_parser_impl
std::string m_selection
 
std::string::iterator m_p
 
std::string::iterator m_end
 
int m_lookahead
 
std::string m_token
 

Detailed Description

Definition at line 1172 of file tls.cpp.

Member Enumeration Documentation

◆ TOKEN

Enumerator
bt_NONE 
bt_IDENT 
bt_NUMBER 
bt_EOLN 

Definition at line 1180 of file tls.cpp.

Constructor & Destructor Documentation

◆ TLSSelectionParserImplBuster()

cif::TLSSelectionParserImplBuster::TLSSelectionParserImplBuster ( const std::string &  selection)

Definition at line 1201 of file tls.cpp.

1202  : tls_selection_parser_impl(selection)
1203 {
1205 }
tls_selection_parser_impl(const std::string &selection)
Definition: tls.cpp:613

Member Function Documentation

◆ get_next_token()

int cif::TLSSelectionParserImplBuster::get_next_token ( )
protectedvirtual

Implements cif::tls_selection_parser_impl.

Definition at line 1207 of file tls.cpp.

1208 {
1209  int result = bt_NONE;
1210  enum STATE
1211  {
1212  st_START,
1213  st_NEGATE,
1214  st_NUM,
1215  st_IDENT
1216  } state = st_START;
1217 
1218  m_value_i = 0;
1219  m_value_s.clear();
1220  bool negative = false;
1221 
1222  while (result == bt_NONE)
1223  {
1224  char ch = *m_p++;
1225  if (m_p > m_end)
1226  ch = 0;
1227 
1228  switch (state)
1229  {
1230  case st_START:
1231  if (ch == 0)
1232  result = bt_EOLN;
1233  else if (isspace(ch))
1234  continue;
1235  else if (isdigit(ch))
1236  {
1237  m_value_i = ch - '0';
1238  state = st_NUM;
1239  }
1240  else if (isalpha(ch))
1241  {
1242  m_value_s = { ch };
1243  state = st_IDENT;
1244  }
1245  else if (ch == '-')
1246  {
1247  state = st_NEGATE;
1248  }
1249  else
1250  result = ch;
1251  break;
1252 
1253  case st_NEGATE:
1254  if (isdigit(ch))
1255  {
1256  m_value_i = ch - '0';
1257  state = st_NUM;
1258  negative = true;
1259  }
1260  else
1261  {
1262  --m_p;
1263  result = '-';
1264  }
1265  break;
1266 
1267  case st_NUM:
1268  if (isdigit(ch))
1269  m_value_i = 10 * m_value_i + (ch - '0');
1270  else
1271  {
1272  if (negative)
1273  m_value_i = -m_value_i;
1274 
1275  result = bt_NUMBER;
1276  --m_p;
1277  }
1278  break;
1279 
1280  case st_IDENT:
1281  if (isalnum(ch))
1282  m_value_s += ch;
1283  else
1284  {
1285  --m_p;
1286  result = bt_IDENT;
1287  }
1288  break;
1289  }
1290  }
1291 
1292  return result;
1293 }
std::string::iterator m_end
Definition: tls.cpp:628
std::string::iterator m_p
Definition: tls.cpp:628

◆ Parse()

std::unique_ptr< tls_selection > cif::TLSSelectionParserImplBuster::Parse ( )
virtual

Implements cif::tls_selection_parser_impl.

Definition at line 1417 of file tls.cpp.

1418 {
1419  std::unique_ptr<tls_selection> result = ParseGroup();
1420  match(bt_EOLN);
1421  return result;
1422 }
virtual void match(int token)
Definition: tls.cpp:633
std::unique_ptr< tls_selection > ParseGroup()
Definition: tls.cpp:1309

◆ ParseAtom()

std::tuple< std::string, int > cif::TLSSelectionParserImplBuster::ParseAtom ( )
protected

Definition at line 1383 of file tls.cpp.

1384 {
1385  std::string chain = m_value_s;
1386  int seqNr = kResidueNrWildcard;
1387 
1388  if (m_lookahead == '*')
1389  match('*');
1390  else
1391  match(bt_IDENT);
1392 
1393  match('|');
1394 
1395  if (m_lookahead == '*')
1396  match('*');
1397  else
1398  {
1399  seqNr = m_value_i;
1400  match(bt_NUMBER);
1401 
1402  if (m_lookahead == ':')
1403  {
1404  match(':');
1405  std::string atom = m_value_s;
1406 
1407  if (cif::VERBOSE > 0)
1408  std::cerr << "Warning: ignoring atom ID '" << atom << "' in TLS selection" << std::endl;
1409 
1410  match(bt_IDENT);
1411  }
1412  }
1413 
1414  return std::make_tuple(chain, seqNr);
1415 }
virtual void match(int token)
Definition: tls.cpp:633
int VERBOSE
Definition: utilities.cpp:58
const int kResidueNrWildcard
Definition: tls.cpp:40

◆ ParseGroup()

std::unique_ptr< tls_selection > cif::TLSSelectionParserImplBuster::ParseGroup ( )
protected

Definition at line 1309 of file tls.cpp.

1310 {
1311  std::unique_ptr<tls_selection> result;
1312 
1313  auto add = [&result](const std::string &chainID, int from, int to)
1314  {
1315  std::unique_ptr<tls_selection> sc(new tls_selection_chain(chainID));
1316  std::unique_ptr<tls_selection> sr(new tls_selection_range_seq(from, to));
1317  std::unique_ptr<tls_selection> s(new tls_selection_intersection(sc, sr));
1318 
1319  if (result == nullptr)
1320  result.reset(s.release());
1321  else
1322  result.reset(new tls_selection_union{ result, s });
1323  };
1324 
1325  match('{');
1326 
1327  do
1328  {
1329  std::string chain1;
1330  int seqNr1;
1331  std::tie(chain1, seqNr1) = ParseAtom();
1332 
1333  if (m_lookahead == '-')
1334  {
1335  std::string chain2;
1336  int seqNr2 = seqNr1;
1337 
1338  match('-');
1339 
1340  if (m_lookahead == bt_NUMBER)
1341  {
1342  seqNr2 = m_value_i;
1343  match(bt_NUMBER);
1344  }
1345  else
1346  {
1347  std::tie(chain2, seqNr2) = ParseAtom();
1348  if (chain1 != chain2)
1349  {
1350  std::cerr << "Warning, ranges over multiple chains detected" << std::endl;
1351 
1352  std::unique_ptr<tls_selection> sc1(new tls_selection_chain(chain1));
1353  std::unique_ptr<tls_selection> sr1(new tls_selection_range_seq(seqNr1, kResidueNrWildcard));
1354  std::unique_ptr<tls_selection> s1(new tls_selection_intersection(sc1, sr1));
1355 
1356  std::unique_ptr<tls_selection> sc2(new tls_selection_chain(chain2));
1357  std::unique_ptr<tls_selection> sr2(new tls_selection_range_seq(kResidueNrWildcard, seqNr2));
1358  std::unique_ptr<tls_selection> s2(new tls_selection_intersection(sc2, sr2));
1359 
1360  std::unique_ptr<tls_selection> s(new tls_selection_union(s1, s2));
1361 
1362  if (result == nullptr)
1363  result.reset(s.release());
1364  else
1365  result.reset(new tls_selection_union{ result, s });
1366 
1367  chain1.clear();
1368  }
1369  }
1370 
1371  if (not chain1.empty())
1372  add(chain1, seqNr1, seqNr2);
1373  }
1374  else
1375  add(chain1, seqNr1, seqNr1);
1376  } while (m_lookahead != '}');
1377 
1378  match('}');
1379 
1380  return result;
1381 }
std::tuple< std::string, int > ParseAtom()
Definition: tls.cpp:1383
virtual void match(int token)
Definition: tls.cpp:633
const int kResidueNrWildcard
Definition: tls.cpp:40

◆ ParseOldGroup()

std::unique_ptr<tls_selection> cif::TLSSelectionParserImplBuster::ParseOldGroup ( )
protected

◆ to_string()

std::string cif::TLSSelectionParserImplBuster::to_string ( int  token)
protectedvirtual

Implements cif::tls_selection_parser_impl.

Definition at line 1295 of file tls.cpp.

1296 {
1297  switch (token)
1298  {
1299  case bt_IDENT: return "identifier (" + m_value_s + ')';
1300  case bt_NUMBER: return "number (" + to_string(m_value_i) + ')';
1301  case bt_EOLN: return "end of line";
1302 
1303  default:
1304  assert(false);
1305  return "unknown token";
1306  }
1307 }
virtual std::string to_string(int token)
Definition: tls.cpp:1295

Member Data Documentation

◆ m_parsing_old_style

bool cif::TLSSelectionParserImplBuster::m_parsing_old_style = false
protected

Definition at line 1198 of file tls.cpp.

◆ m_value_i

int cif::TLSSelectionParserImplBuster::m_value_i
protected

Definition at line 1196 of file tls.cpp.

◆ m_value_s

std::string cif::TLSSelectionParserImplBuster::m_value_s
protected

Definition at line 1197 of file tls.cpp.


The documentation for this class was generated from the following file: