FOSSology  4.4.0
Open Source License Compliance by Open Source Software
files.hpp
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2013-2014 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #ifndef FILES_HPP_
8 #define FILES_HPP_
9 
10 #include <string>
11 #include <glib.h>
12 
18 namespace fo
19 {
20 
25  class File
26  {
27  public:
28  File(unsigned long id, const char* fileName);
29  File(unsigned long id, std::string const& fileName);
30 
31  unsigned long getId() const;
32  std::string getContent(const unsigned long int maximumBytes = 1 << 20) const;
33  const std::string& getFileName() const;
34  bool isReadable() const;
35  private:
36  unsigned long id;
37  std::string fileName;
38  };
39 
40  std::string getStringFromFile(const char* filename, const unsigned long int maximumBytes = 1 << 20);
41  std::string getStringFromFile(std::string const& filename, const unsigned long int maximumBytes = 1 << 20);
42 }
43 
44 #endif /* FILES_HPP_ */
Class to handle file related operations.
Definition: files.hpp:26
std::string getContent(const unsigned long int maximumBytes=1<< 20) const
Get the content of the file limited by maximumBytes.
Definition: files.cc:81
bool isReadable() const
Definition: files.cc:124
unsigned long getId() const
Definition: files.cc:115
unsigned long id
ID of the file.
Definition: files.hpp:36
std::string fileName
Path of the file.
Definition: files.hpp:37
File(unsigned long id, const char *fileName)
Definition: files.cc:100
const std::string & getFileName() const
Definition: files.cc:90
fo namespace holds the FOSSology library functions.
std::string getStringFromFile(const char *filename, const unsigned long int maximumBytes)
Reads the content of a file and return it as a string.
Definition: files.cc:34