2008-01-14 01:01:11 +01:00
|
|
|
/*
|
|
|
|
|
QUERY.hpp - interface for capability queries
|
|
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2008-01-14 01:01:11 +01:00
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
#ifndef LUMIERA_QUERY_H
|
|
|
|
|
#define LUMIERA_QUERY_H
|
2008-01-14 01:01:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
2008-02-10 17:23:16 +01:00
|
|
|
#include <typeinfo>
|
2008-01-14 01:01:11 +01:00
|
|
|
|
2008-02-18 04:16:53 +01:00
|
|
|
#include <boost/format.hpp>
|
2008-01-14 01:01:11 +01:00
|
|
|
|
|
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
namespace lumiera
|
2008-01-14 01:01:11 +01:00
|
|
|
{
|
|
|
|
|
using std::string;
|
2008-02-18 04:16:53 +01:00
|
|
|
using boost::format;
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
/* ==== comon definitions for rule based queries ==== */
|
2008-01-14 01:01:11 +01:00
|
|
|
|
2008-02-10 17:23:16 +01:00
|
|
|
typedef const char * const Symbol;
|
|
|
|
|
|
|
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
/**
|
|
|
|
|
* Generic query interface for retrieving objects matching
|
|
|
|
|
* some capability query
|
|
|
|
|
*/
|
2008-02-10 17:23:16 +01:00
|
|
|
template<class OBJ>
|
2008-01-14 01:01:11 +01:00
|
|
|
class Query : public std::string
|
|
|
|
|
{
|
|
|
|
|
public:
|
2008-02-18 04:16:53 +01:00
|
|
|
explicit Query (const string& predicate="") : string(predicate) {}
|
|
|
|
|
explicit Query (format& pattern) : string(str(pattern)) {}
|
|
|
|
|
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
const string asKey() const
|
|
|
|
|
{
|
|
|
|
|
return string(typeid(OBJ).name())+": "+*this;
|
|
|
|
|
}
|
2008-01-14 01:01:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace query
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** ensure standard format for a given id string.
|
|
|
|
|
* Trim, sanitize and ensure the first letter is lower case.
|
|
|
|
|
* @note modifies the given string ref in place
|
|
|
|
|
*/
|
|
|
|
|
void normalizeID (string& id);
|
|
|
|
|
|
2008-02-18 04:16:53 +01:00
|
|
|
|
2008-03-31 03:21:28 +02:00
|
|
|
/** count the top-level predicates in the query string.
|
|
|
|
|
* usable for ordering queries, as more predicates usually
|
|
|
|
|
* mean more conditions, i.e. more constriction
|
|
|
|
|
*/
|
|
|
|
|
uint countPraed (const string&);
|
2008-02-18 04:16:53 +01:00
|
|
|
|
2008-04-06 08:56:18 +02:00
|
|
|
|
|
|
|
|
const string extractID (Symbol, const string& termString);
|
|
|
|
|
|
|
|
|
|
const string removeTerm (Symbol, string& termString);
|
|
|
|
|
|
|
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
} // namespace query
|
|
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
} // namespace lumiera
|
2008-01-14 01:01:11 +01:00
|
|
|
#endif
|