OpenStructure
Loading...
Searching...
No Matches
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
40
41namespace ost { namespace mol {
42
62 typedef enum {
63 EXCLUSIVE_BONDS=1,
64 NO_BONDS=2,
65 MATCH_RESIDUES=4
66 } Flag;
67};
68
70
75public:
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;
116private:
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.
linear chain of residues
Protein or molecule.
definition of EntityView
Selection Query.
Definition query.hh:74
bool IsChainSelected(const ChainHandle &chain) const
whether chain fulfills the query
impl::QueryImplP Impl()
const String & GetQueryString() const
Get String.
bool MatchAll() const
const impl::QueryImplP & Impl() 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
bool IsResidueSelected(const ResidueHandle &residue) const
whether residue fulfills the query
bool IsAtomSelected(const AtomHandle &ah) const
whether atom fulfills the query
const QueryErrorDesc & GetErrorDescription() const
Holds state used during query evaluation.
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