FOSSology  4.6.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;
46  bool is_enabled;
47  match(const int s, const int e, const string& t, bool enabled = true)
48  : start(s), end(e), type(t), is_enabled(enabled) { }
49 } ;
50 
51 bool operator==(const match& m1, const match& m2);
52 bool operator!=(const match& m1, const match& m2);
53 
58 class scanner
59 {
60 public:
61  virtual ~scanner() {};
62 
68  virtual void ScanString(const string& s, list<match>& results) const = 0;
69 
77  virtual void ScanFile(const string& fileName, list<match>& results) const
78  {
79  string s;
80  ReadFileToString(fileName, s);
81  ScanString(s, results);
82  }
83 } ;
84 
85 #endif
86 
Abstract class to provide interface to scanners.
Definition: scanners.hpp:59
virtual void ScanFile(const string &fileName, list< match > &results) const
Helper function to scan file.
Definition: scanners.hpp:77
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
bool is_enabled
Definition: scanners.hpp:46