Files
Sourcetrail/src/lib/data/graph/Graph.h
T
Eberhard Graether c84972b96e logic: added query syntax and filtering system for search
This change allows the user to use a simple query syntax in the search field to filter the results using names,
operators and predefined filters.

The class QueryTree is capable of parsing a simple query language consiting of QueryNodes, subclassed as
QueryOperators, QueryCommands and QueryTokens. QueryToken identifies a Token by name. QueryCommand represents predefined
filters. QueryOperator defines the syntactic relationship.

QueryNode examples:
	"A" -> QueryToken that identifies the Token named A
	class -> QueryCommand that filters all Nodes that are classes
	. -> QueryOperator that concatenates filters

QueryExamples:
	"A".class -> All Tokens named A that are classes
	method.(private|protected) -> All methods that are private or protected
	"A".member -> All members of A
	"A":field.!const -> All fields of A that are not const (':' can be used instead of '.member')

QueryTree checks for correct operator precedence and validity of the query.
All QueryCommands can be found in data/query/QueryCommand.cpp
All QueryOperators can be found in data/query/QueryOperator.cpp

The parsed QueryTree is then passed to the class GraphFilterConductor, which is capable of applying the query on a
Graph. Each part of the query gets assigned a GraphFilter that filters the input Graph in order of node precedence. The
class SubGraph is used as intermediate container, only holding bare pointers to Nodes and Edges. The output Graph holds
all Nodes that match the query.

MessageActivateTokens is used to show all of the results in the CodeView. The GraphView currently only shows the first
Node of the results.

bug id = #6
2014-08-30 18:24:00 +02:00

83 lines
2.4 KiB
C++

#ifndef GRAPH_H
#define GRAPH_H
#include <map>
#include <memory>
#include <deque>
#include "data/graph/Edge.h"
#include "data/graph/FilterableGraph.h"
#include "data/graph/Node.h"
class Graph
: public FilterableGraph
{
public:
Graph();
virtual ~Graph();
// FilterableGraph implementation
virtual void copy(const FilterableGraph* other);
virtual void clear();
virtual void add(const FilterableGraph* other);
virtual void forEachNode(std::function<void(Node*)> func) const;
virtual void forEachEdge(std::function<void(Edge*)> func) const;
virtual void forEachToken(std::function<void(Token*)> func) const;
virtual void addNode(Node* node);
virtual void addEdge(Edge* edge);
virtual size_t getNodeCount() const;
virtual size_t getEdgeCount() const;
const std::map<Id, std::shared_ptr<Node>>& getNodes() const;
const std::map<Id, std::shared_ptr<Edge>>& getEdges() const;
Node* getNode(const std::string& fullName) const;
Edge* getEdge(Edge::EdgeType type, Node* from, Node* to) const;
Node* getNodeById(Id id) const;
Edge* getEdgeById(Id id) const;
Token* getTokenById(Id id) const;
Node* createNodeHierarchy(const std::string& fullName);
Node* createNodeHierarchy(Node::NodeType type, const std::string& fullName);
Node* createNodeHierarchyWithDistinctSignature(const std::string& fullName, const std::string& signature);
Node* createNodeHierarchyWithDistinctSignature(
Node::NodeType type, const std::string& fullName, const std::string& signature
);
Edge* createEdge(Edge::EdgeType type, Node* from, Node* to);
void removeNode(Node* node);
void removeEdge(Edge* edge);
Node* findNode(std::function<bool(Node*)> func) const;
Edge* findEdge(std::function<bool(Edge*)> func) const;
Token* findToken(std::function<bool(Token*)> func) const;
Node* addNodeAsPlainCopy(Node* node);
Edge* addEdgeAsPlainCopy(Edge* edge);
private:
static const std::string DELIMITER;
Node* getLastValidNode(std::deque<std::string>* names) const;
Node* insertNodeHierarchy(Node::NodeType type, std::deque<std::string> names, Node* parentNode);
Node* insertNode(Node::NodeType type, const std::string& name, Node* parentNode);
Edge* insertEdge(Edge::EdgeType type, Node* from, Node* to);
void removeEdgeInternal(Edge* edge);
const std::string m_delimiter;
std::map<Id, std::shared_ptr<Node>> m_nodes;
std::map<Id, std::shared_ptr<Edge>> m_edges;
};
std::ostream& operator<<(std::ostream& ostream, const Graph& graph);
#endif // GRAPH_H