]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
54569babb6d54f506c1734388df106814d66c511
[lyx.git] / src / support / lyxlib.h
1 // -*- C++ -*-
2 /**
3  * \file lyxlib.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * A selection of useful system functions made
8  * handy for C++ usage.
9  *
10  * \author Lars Gullik Bjønnes
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef LYX_LIB_H
16 #define LYX_LIB_H
17
18 #include <string>
19
20
21 namespace lyx {
22 namespace support {
23
24 /// get the current working directory
25 std::string const getcwd();
26 /// change to a directory, 0 is returned on success.
27 int chdir(std::string const & name);
28 /**
29  * rename a file, returns false if it fails.
30  * It can handle renames across partitions.
31  */
32 bool rename(std::string const & from, std::string const & to);
33 /// copy a file, returns false it it fails
34 bool copy(std::string const & from, std::string const & to);
35 /// generates a checksum of a file
36 unsigned long sum(std::string const & file);
37 /// FIXME: some point to this hmm ?
38 int kill(int pid, int sig);
39 /// FIXME: same here
40 void abort();
41 /// create the given directory with the given mode
42 int mkdir(std::string const & pathname, unsigned long int mode);
43 /// put variable=value as a C std::string into the environment
44 bool putenv(std::string const & varname, std::string const & value);
45 /// unlink the given file
46 int unlink(std::string const & file);
47 /// remove the given directory
48 int rmdir(std::string const & file);
49 /// convert the given string to an integer
50 int atoi(std::string const & nstr);
51 /// (securely) create a temporary file in the given dir with the given prefix
52 std::string const tempName(std::string const & dir = std::string(),
53                       std::string const & mask = std::string());
54
55
56 /**
57  * Returns true if var is approximately equal to number with allowed error
58  * of 'error'.
59  *
60  * Usage: if (float_equal(var, number, 0.0001)) { }
61  *
62  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
63  */
64 inline bool float_equal(double var, double number, double error)
65 {
66         return (number - error <= var && var <= number + error);
67 }
68
69 } // namespace support
70 } // namespace lyx
71
72 #endif /* LYX_LIB_H */