]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
lyxserver cleanup patch + andre's small patches
[lyx.git] / src / support / lyxlib.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef LYX_LIB_H
13 #define LYX_LIB_H
14
15 #include "LString.h"
16
17 // Where can I put this?  I found the occurence of the same code
18 // three/four times. Don't you think it better to use a macro definition
19 // (an inlined member of some class)?
20
21 // Use a namespace if we can, a struct otherwise
22 namespace lyx {
23
24 ///
25 string const getcwd();
26 ///
27 int chdir(string const & name);
28 /// Returns false if it fails
29 bool rename(string const & from, string const & to);
30 /// Returns false it it fails
31 bool copy(string const & from, string const & to);
32 /// generates a checksum
33 unsigned long sum(string const & file);
34 /// returns a date string (not used currently)
35 char * date(); 
36 /// returns the name of the user (not used currently)
37 string const getUserName();
38 ///
39 int kill(int pid, int sig);
40 ///
41 void abort();
42 ///
43 int mkdir(string const & pathname, unsigned long int mode);
44 ///
45 int putenv(char const * str);
46 ///
47 int unlink(string const & file);
48 ///
49 int rmdir(string const & file);
50 ///
51 int atoi(string const & nstr);
52 ///
53 string const tempName(string const & dir = string(),
54                       string const & mask = string());
55
56
57 /** Returns true if var is approximately equal to number with allowed error
58  * of 'error'.
59  *
60  * Reason: A float can be very close to the number, yet still need not be 
61  * exactly equal, you can have exp(-10) which is very close to zero but not
62  * zero. If you only need an approximate equality (you usually do), use this
63  * template.
64  *
65  * Usage: if (float_equal(var, number, 0.0001)) { }
66  * 
67  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
68  */
69 inline bool float_equal(float var, float number, float error)
70 {
71         return (number - error <= var && var <= number + error);
72 }
73
74 } // namespace lyx
75 #endif /* LYX_LIB_H */