Tulip  4.8.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
TlpTools.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef _TLPTOOLS_H
21 #define _TLPTOOLS_H
22 
23 #include <iostream>
24 #include <climits>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <tulip/tulipconf.h>
28 
29 #ifdef WIN32
30 typedef struct _stat tlp_stat_t;
31 #else
32 typedef struct stat tlp_stat_t;
33 #endif
34 
35 namespace tlp {
36 extern TLP_SCOPE const char PATH_DELIMITER;
37 extern TLP_SCOPE std::string TulipLibDir;
38 extern TLP_SCOPE std::string TulipPluginsPath;
39 extern TLP_SCOPE std::string TulipBitmapDir;
40 extern TLP_SCOPE std::string TulipShareDir;
41 
42 /**
43  * @ingroup Plugins
44  *
45  * @brief Initializes the Tulip library.
46  * Looks for the Tulip plug-ins directory.
47  * The plug-ins directory can be defined in different ways, given by order of prevalence :
48  * 1. the TLP_DIR environment variable, if it has a value
49  * 2. the appDirPath parameter, if it is not NULL
50  * 3. at that point, the Tulip paths will be retrieved from the path of the loaded Tulip shared library
51  * (you must dispose of a standard Tulip installation for that feature to work).
52  * 4. a fallback value of 'C:/Tulip/lib/' on windows, or '/usr/local/lib/' on Unix.
53  */
54 extern TLP_SCOPE void initTulipLib(const char* appDirPath = NULL);
55 
56 /**
57  * @ingroup Plugins
58  *
59  * @brief Demangles the name of a C++ class
60  * @param className The mangled name of a class
61  * @param hideTlp a flag to indicate if the 'tlp::' prefix
62  * @return string The demangled name of a Tulip C++ class.
63  */
64 TLP_SCOPE std::string demangleClassName(const char *className,
65  bool hideTlp = false);
66 
67 /**
68  * @ingroup Plugins
69  *
70  * @brief Demangles the name of a C++ class defined in the tlp namespace.
71  * @param className The mangled name of a class
72  * @return string The demangled name of a Tulip C++ class
73  * without the tlp:: prefix
74  */
75 inline std::string demangleTlpClassName(const char *className) {
76  return demangleClassName(className, true);
77 }
78 
79 /**
80  * @brief Returns an istream to read from a gzipped file (uses gzstream lib).
81  * The stream has to be deleted after use.
82  * @param name The name of the file to read from.
83  * @param open_mode The mode to open the file with. Defaults to std::ios::in.
84  * @return istream gzipped input stream from a file.
85  */
86 TLP_SCOPE std::istream *getIgzstream(const std::string &name, int open_mode = std::ios::in);
87 
88 /**
89  * @brief Returns an ostream to write to a gzipped file (uses gzstream lib).
90  * The stream has to be deleted after use.
91  * @warning Don't forget to check the stream with ios::bad()!
92  * @param name The name of the file to write to.
93  * @param open_mode The mode to open the file with. Defaults to std::ios::out.
94  * @return ostream gzipped output stream to a file.
95  */
96 TLP_SCOPE std::ostream *getOgzstream(const std::string &name, int open_mode = std::ios::out);
97 
98 /**
99  * @brief give the value of the seed used for further initialization
100  * of a random sequence (with further calls to rand() or rand_r(...)).
101  * @param seed the value of the seed.
102  * Set seed to UINT_MAX if you need a random choice of the seed.
103  */
104 TLP_SCOPE void setSeedOfRandomSequence(unsigned int seed = UINT_MAX);
105 
106 /**
107  * @brief return the value of the seed used for further initialization
108  * of a random sequence
109  */
110 TLP_SCOPE unsigned int getSeedOfRandomSequence();
111 
112 /**
113  * @brief initialize a random sequence with the seed previously set
114  * Further calls to rand() or rand_r(...) will return the elements of
115  * that sequence
116  */
117 TLP_SCOPE void initRandomSequence();
118 
119 /**
120  * @brief Cross-platform function to stat a path on a filesystem. Its purpose is to support
121  * paths on windows platform containing non-ascii characters.
122  * @param pathname an utf-8 encoded string containing the path name to stat
123  * @param buf a pointer to a tlp_stat_t structure (a typedef for struct stat)
124  */
125 TLP_SCOPE int statPath(const std::string &pathname, tlp_stat_t *buf);
126 
127 /**
128  * @brief Cross-platform function to get an input file stream. Its purpose is to support
129  * paths on windows platform containing non-ascii characters.
130  * @param filename an utf-8 encoded string containing the path of the file to open for performing input operations
131  * @param open_mode the stream opening mode flags (bitwise combination of std::ios_base::openmode constants).
132  */
133 TLP_SCOPE std::istream *getInputFileStream(const std::string &filename, std::ios_base::openmode open_mode = std::ios::in);
134 
135 /**
136  * @brief Cross-platform function to get an output file stream. Its purpose is to support
137  * paths on windows platform containing non-ascii characters.
138  * @param filename an utf-8 encoded string containing the path of the file to open for performing output operations
139  * @param open_mode the stream opening mode flags (bitwise combination of std::ios_base::openmode constants).
140  */
141 TLP_SCOPE std::ostream *getOutputFileStream(const std::string &filename, std::ios_base::openmode open_mode = std::ios::out);
142 
143 }
144 
145 #endif
void initTulipLib(const char *appDirPath=NULL)
Initializes the Tulip library. Looks for the Tulip plug-ins directory. The plug-ins directory can be ...
std::string demangleTlpClassName(const char *className)
Demangles the name of a C++ class defined in the tlp namespace.
Definition: TlpTools.h:75
std::string demangleClassName(const char *className, bool hideTlp=false)
Demangles the name of a C++ class.