libqasm
library for handling cQASM files
cqasm-version.hpp
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <string>
8 #include <cstdint>
9 #include <complex>
10 #include <vector>
11 
12 namespace cqasm {
13 
17 namespace version {
18 
22 class Version : public std::vector<std::int64_t> {
23 public:
24 
28  explicit Version(const std::string &version = "1.0");
29 
37  int compare(const Version &other) const;
38 
46  int compare(const std::string &other) const;
47 
48 };
49 
53 std::ostream &operator<<(std::ostream &os, const Version &object);
54 
59 Version parse_file(const std::string &filename);
60 
66 Version parse_file(FILE *file, const std::string &filename = "<unknown>");
67 
73 Version parse_string(const std::string &data, const std::string &filename="<unknown>");
74 
78 class ParseHelper {
79 public:
80 
84  FILE *fptr = nullptr;
85 
89  void *buf = nullptr;
90 
94  void *scanner = nullptr;
95 
99  std::string filename;
100 
105 
106 private:
107  friend Version parse_file(const std::string &filename);
108  friend Version parse_file(FILE *file, const std::string &filename);
109  friend Version parse_string(const std::string &data, const std::string &filename);
110 
117  ParseHelper(const std::string &filename, const std::string &data, bool use_file);
118 
123  ParseHelper(const std::string &filename, FILE *fptr);
124 
128  bool construct();
129 
133  void parse();
134 
135 public:
136 
140  virtual ~ParseHelper();
141 
145  static void push_error(const std::string &error);
146 
147 };
148 
149 } // namespace version
150 } // namespace cqasm
Version version
The parse result.
Version parse_file(const std::string &filename)
Parse the given file to get its version number.
Toplevel namespace with entry points for the new API.
Version(const std::string &version="1.0")
Constructs a version object from a string, defaulting to 1.0.
Version number primitive used within the AST and semantic trees.
std::ostream & operator<<(std::ostream &os, const Version &object)
Stream << overload for version nodes.
Internal helper class for parsing cQASM file versions.
std::string filename
Name of the file being parsed.
Version parse_string(const std::string &data, const std::string &filename)
Parse the given string as a file to get its version number.
int compare(const Version &other) const
Compares this version against the other version.