souffle  2.0.2-371-g6315b36
QualifiedName.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file QualifiedName.h
12  *
13  * Defines the qualified name class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
20 #include <algorithm>
21 #include <sstream>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 namespace souffle::ast {
27 
28 /**
29  * @class QualifiedName
30  * @brief Qualified Name class defines fully/partially qualified names
31  * to identify objects in components.
32  */
33 class QualifiedName {
34 public:
35  QualifiedName() : qualifiers() {}
36  QualifiedName(const std::string& name) : qualifiers({name}) {}
37  QualifiedName(const char* name) : QualifiedName(std::string(name)) {}
38  QualifiedName(const std::vector<std::string> qualifiers) : qualifiers(qualifiers) {}
39  QualifiedName(const QualifiedName&) = default;
40  QualifiedName(QualifiedName&&) = default;
43 
44  /** append qualifiers */
45  void append(std::string name) {
46  qualifiers.push_back(std::move(name));
47  }
48 
49  /** prepend qualifiers */
50  void prepend(std::string name) {
51  qualifiers.insert(qualifiers.begin(), std::move(name));
52  }
53 
54  /** check for emptiness */
55  bool empty() const {
56  return qualifiers.empty();
57  }
58 
59  /** get qualifiers */
60  const std::vector<std::string>& getQualifiers() const {
61  return qualifiers;
62  }
63 
64  /** convert to a string separated by fullstop */
65  std::string toString() const {
66  std::stringstream ss;
67  ss << join(qualifiers, ".");
68  return ss.str();
69  }
70 
71  bool operator==(const QualifiedName& other) const {
72  return qualifiers == other.qualifiers;
73  }
74 
75  bool operator!=(const QualifiedName& other) const {
76  return !(*this == other);
77  }
78 
79  bool operator<(const QualifiedName& other) const {
80  return std::lexicographical_compare(
81  qualifiers.begin(), qualifiers.end(), other.qualifiers.begin(), other.qualifiers.end());
82  }
83 
84  /** print qualified name */
85  void print(std::ostream& out) const {
86  out << join(qualifiers, ".");
87  }
88 
89  friend std::ostream& operator<<(std::ostream& out, const QualifiedName& id) {
90  id.print(out);
91  return out;
92  }
93 
94 private:
95  /* array of name qualifiers */
96  std::vector<std::string> qualifiers;
97 };
98 
99 inline QualifiedName operator+(const std::string& name, const QualifiedName& id) {
100  QualifiedName res = id;
101  res.prepend(name);
102  return res;
103 }
104 
105 } // namespace souffle::ast
souffle::ast::QualifiedName::getQualifiers
const std::vector< std::string > & getQualifiers() const
get qualifiers
Definition: QualifiedName.h:66
souffle::ast::QualifiedName::qualifiers
std::vector< std::string > qualifiers
Definition: QualifiedName.h:102
souffle::ast::QualifiedName::QualifiedName
QualifiedName()
Definition: QualifiedName.h:41
souffle::ast::QualifiedName::print
void print(std::ostream &out) const
print qualified name
Definition: QualifiedName.h:91
souffle::ast::QualifiedName::empty
bool empty() const
check for emptiness
Definition: QualifiedName.h:61
souffle::ast::QualifiedName::operator=
QualifiedName & operator=(const QualifiedName &)=default
souffle::ast::QualifiedName::operator!=
bool operator!=(const QualifiedName &other) const
Definition: QualifiedName.h:81
souffle::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
souffle::ast::QualifiedName::append
void append(std::string name)
append qualifiers
Definition: QualifiedName.h:51
souffle::ast::operator+
QualifiedName operator+(const std::string &name, const QualifiedName &id)
Definition: QualifiedName.h:105
souffle::ast::QualifiedName::toString
std::string toString() const
convert to a string separated by fullstop
Definition: QualifiedName.h:71
souffle::ast::QualifiedName::operator<<
friend std::ostream & operator<<(std::ostream &out, const QualifiedName &id)
Definition: QualifiedName.h:95
std
Definition: Brie.h:3053
souffle::ast::QualifiedName::prepend
void prepend(std::string name)
prepend qualifiers
Definition: QualifiedName.h:56
StreamUtil.h
souffle::ast::QualifiedName::operator<
bool operator<(const QualifiedName &other) const
Definition: QualifiedName.h:85
souffle::ast::QualifiedName::operator==
bool operator==(const QualifiedName &other) const
Definition: QualifiedName.h:77
souffle::ast
Definition: Aggregator.h:35
souffle::ast::QualifiedName
Qualified Name class defines fully/partially qualified names to identify objects in components.
Definition: QualifiedName.h:39
id
void id(std::string col)
Definition: Tui.h:1124
souffle::profile::ss
class souffle::profile::Tui ss
Definition: Tui.h:336