]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
4e6cf32322c2b5c43ffa403bc001655b59e1ccde
[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/FileName.h"
19
20 #include <string>
21
22
23 namespace lyx {
24 namespace support {
25
26 /// get the current working directory
27 FileName const getcwd();
28
29 /**
30  * rename a file, returns false if it fails.
31  * It can handle renames across partitions.
32  */
33 bool rename(FileName const & from, FileName const & to);
34 /// copy a file, returns false it it fails
35 bool copy(FileName const & from, FileName const & to,
36           unsigned long int mode = (unsigned long int)-1);
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 /// \ret return 0 if the directory is successfully created
43 int mkdir(FileName const & pathname, unsigned long int mode);
44 /// create the given directory with the given mode, create all
45 /// intermediate directories if necessary
46 /// \ret return 0 if the directory is successfully created
47 int makedir(char * pathname, unsigned long int mode=0755);
48 /// (securely) create a temporary file in the given dir with the given mask
49 /// \p mask must be in filesystem encoding
50 FileName const tempName(FileName const & dir = FileName(),
51                       std::string const & mask = std::string());
52
53
54 /**
55  * Returns true if var is approximately equal to number with allowed error
56  * of 'error'.
57  *
58  * Usage: if (float_equal(var, number, 0.0001)) { }
59  *
60  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
61  */
62 inline bool float_equal(double var, double number, double error)
63 {
64         return (number - error <= var && var <= number + error);
65 }
66
67 } // namespace support
68 } // namespace lyx
69
70 #endif /* LYX_LIB_H */