OpenStructure
query.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_QUERY_HF
20 #define OST_QUERY_HF
21 
22 /*
23  Author: Marco Biasini
24  */
25 
26 #include <string>
27 #include <vector>
28 #include <set>
29 
30 #include <boost/variant.hpp>
31 #include <boost/logic/tribool.hpp>
32 
33 #include <ost/range.hh>
34 
35 #include <ost/mol/module_config.hh>
37 #include <ost/mol/query_error.hh>
38 #include <ost/mol/atom_handle.hh>
39 #include <ost/mol/query_state.hh>
40 
41 namespace ost { namespace mol {
42 
62  typedef enum {
63  EXCLUSIVE_BONDS=1,
64  NO_BONDS=2,
65  MATCH_RESIDUES=4
66  } Flag;
67 };
68 
69 typedef uint QueryFlags;
70 
75 public:
77  Query(const String& query_string="");
78 
80  Query(const impl::QueryImplP& impl);
81 
83  bool IsAtomSelected(const AtomHandle& ah) const;
84 
89  bool IsChainSelected(const ChainHandle& chain) const;
90 
95  bool IsResidueSelected(const ResidueHandle& residue) const;
96 
98  const String& GetQueryString() const;
99 
101 
104 
107 
108  // only valid if parsed without error
109  bool IsValid() const;
110  // an empty query String defaults to matching everything
111  bool MatchAll() const;
112 
113  // for internal use only
115  const impl::QueryImplP& Impl() const;
116 private:
117  impl::QueryImplP impl_;
118 };
119 
120 // inlined helper function to quote strings for use in queries (e.g. cname=..).
121 // throws Error if string cannot be quoted
123  // check what quotation marks to use
124  char quote = '\'';
125  if (name.find('\'') != String::npos) {
126  if (name.find('"') != String::npos) {
127  throw Error("Cannot quote chain name " + name + " because it contains "
128  "both ' and \" in its name.");
129  }
130  quote = '"';
131  }
132  // check problematic \ at end (escapes quotation mark and breaks logic)
133  if (name[name.length() - 1] == '\\') {
134  throw Error("Cannot quote chain name " + name + " because it ends in \\.");
135  }
136  return quote + name + quote;
137 }
138 
139 }} // ns
140 
141 #endif
Handle to atom datatype.
Definition: atom_handle.hh:37
linear chain of residues
Definition: chain_handle.hh:52
Protein or molecule.
definition of EntityView
Definition: entity_view.hh:86
Selection Query.
Definition: query.hh:74
bool IsChainSelected(const ChainHandle &chain) const
whether chain fulfills the query
const String & GetQueryString() const
Get String.
const QueryErrorDesc & GetErrorDescription() const
impl::QueryImplP Impl()
bool MatchAll() const
Query(const impl::QueryImplP &impl)
internally used constructor
Query(const String &query_string="")
Construct new query object.
QueryState CreateQueryState(const EntityHandle &view) const
create new query state to be used for a given entity
QueryState CreateQueryState(const EntityView &view) const
create new query state to be used for a given entity
bool IsValid() const
const impl::QueryImplP & Impl() const
bool IsResidueSelected(const ResidueHandle &residue) const
whether residue fulfills the query
bool IsAtomSelected(const AtomHandle &ah) const
whether atom fulfills the query
Holds state used during query evaluation.
Definition: query_state.hh:50
unsigned int uint
Definition: base.hh:29
std::string String
Definition: base.hh:54
#define DLLEXPORT_OST_MOL
boost::shared_ptr< QueryImpl > QueryImplP
uint QueryFlags
Definition: query.hh:69
String DLLEXPORT_OST_MOL QueryQuoteName(const String &name)
Definition: query.hh:122
Definition: base.dox:1
query flags
Definition: query.hh:61