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