]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
0eb2bc031f851dbb46a1d7189444aed25c03abce
[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 "support/std_string.h"
19
20 namespace lyx {
21 namespace support {
22
23 /// get the current working directory
24 string const getcwd();
25 /// change to a directory, 0 is returned on success.
26 int chdir(string const & name);
27 /**
28  * rename a file, returns false if it fails.
29  * It can handle renames across partitions.
30  */
31 bool rename(string const & from, string const & to);
32 /// copy a file, returns false it it fails
33 bool copy(string const & from, string const & to);
34 /// generates a checksum of a file
35 unsigned long sum(string const & file);
36 /// FIXME: some point to this hmm ?
37 int kill(int pid, int sig);
38 /// FIXME: same here
39 void abort();
40 /// create the given directory with the given mode
41 int mkdir(string const & pathname, unsigned long int mode);
42 /// put a C string into the environment
43 int putenv(char const * str);
44 /// unlink the given file
45 int unlink(string const & file);
46 /// remove the given directory
47 int rmdir(string const & file);
48 /// convert the given string to an integer
49 int atoi(string const & nstr);
50 /// (securely) create a temporary file in the given dir with the given prefix
51 string const tempName(string const & dir = string(),
52                       string const & mask = string());
53
54
55 /**
56  * Returns true if var is approximately equal to number with allowed error
57  * of 'error'.
58  *
59  * Usage: if (float_equal(var, number, 0.0001)) { }
60  *
61  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
62  */
63 inline bool float_equal(float var, float number, float error)
64 {
65         return (number - error <= var && var <= number + error);
66 }
67
68 } // namespace support
69 } // namespace lyx
70
71 #endif /* LYX_LIB_H */