FOSSology  4.4.0
Open Source License Compliance by Open Source Software
scanners.hpp
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2015 Siemens AG
3  Author: Florian Krügel
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
11 #ifndef SCANNERS_HPP_
12 #define SCANNERS_HPP_
13 
14 #include <fstream>
15 using std::ifstream;
16 using std::istream;
17 #include <string>
18 using std::string;
19 #include <list>
20 using std::list;
21 
22 bool ReadFileToString(const string& fileName, string& out);
23 
28 struct match {
35  const int start, end;
40  const string& type;
41  match(const int s, const int e, const string& t) : start(s), end(e), type(t) { }
42 } ;
43 
44 bool operator==(const match& m1, const match& m2);
45 bool operator!=(const match& m1, const match& m2);
46 
51 class scanner
52 {
53 public:
54  virtual ~scanner() {};
55 
61  virtual void ScanString(const string& s, list<match>& results) const = 0;
62 
70  virtual void ScanFile(const string& fileName, list<match>& results) const
71  {
72  string s;
73  ReadFileToString(fileName, s);
74  ScanString(s, results);
75  }
76 } ;
77 
78 #endif
79 
Abstract class to provide interface to scanners.
Definition: scanners.hpp:52
virtual void ScanFile(const string &fileName, list< match > &results) const
Helper function to scan file.
Definition: scanners.hpp:70
virtual void ScanString(const string &s, list< match > &results) const =0
Scan the given string and add matches to results.
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:37
bool operator==(const match &m1, const match &m2)
Compare two regex match.
Definition: scanners.cc:34
bool operator!=(const match &m1, const match &m2)
Compare two regex match.
Definition: scanners.cc:44
bool ReadFileToString(const string &fileName, string &out)
Utility: read file to string from scanners.h.
Definition: scanners.cc:21
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308
Store the results of a regex match.
Definition: scanners.hpp:28
const int start
Definition: scanners.hpp:35
const int end
Definition: scanners.hpp:35