Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 00020 #ifndef _TLPTOOLS_H 00021 #define _TLPTOOLS_H 00022 00023 #include <iostream> 00024 #include <climits> 00025 #include <sys/types.h> 00026 #include <sys/stat.h> 00027 #include <tulip/tulipconf.h> 00028 00029 #ifdef WIN32 00030 typedef struct _stat tlp_stat_t; 00031 #else 00032 typedef struct stat tlp_stat_t; 00033 #endif 00034 00035 namespace tlp { 00036 extern TLP_SCOPE const char PATH_DELIMITER; 00037 extern TLP_SCOPE std::string TulipLibDir; 00038 extern TLP_SCOPE std::string TulipPluginsPath; 00039 extern TLP_SCOPE std::string TulipBitmapDir; 00040 extern TLP_SCOPE std::string TulipShareDir; 00041 00042 /** 00043 * @ingroup Plugins 00044 * 00045 * @brief Initializes the Tulip library. 00046 * Looks for the Tulip plug-ins directory. 00047 * The plug-ins directory can be defined in different ways, given by order of prevalence : 00048 * 1. the TLP_DIR environment variable, if it has a value 00049 * 2. the appDirPath parameter, if it is not NULL 00050 * 3. at that point, the Tulip paths will be retrieved from the path of the loaded Tulip shared library 00051 * (you must dispose of a standard Tulip installation for that feature to work). 00052 * 4. a fallback value of 'C:/Tulip/lib/' on windows, or '/usr/local/lib/' on Unix. 00053 */ 00054 extern TLP_SCOPE void initTulipLib(const char* appDirPath = NULL); 00055 00056 /** 00057 * @ingroup Plugins 00058 * 00059 * @brief Demangles the name of a C++ class 00060 * @param className The mangled name of a class 00061 * @param hideTlp a flag to indicate if the 'tlp::' prefix 00062 * @return string The demangled name of a Tulip C++ class. 00063 */ 00064 TLP_SCOPE std::string demangleClassName(const char *className, 00065 bool hideTlp = false); 00066 00067 /** 00068 * @ingroup Plugins 00069 * 00070 * @brief Demangles the name of a C++ class defined in the tlp namespace. 00071 * @param className The mangled name of a class 00072 * @return string The demangled name of a Tulip C++ class 00073 * without the tlp:: prefix 00074 */ 00075 inline std::string demangleTlpClassName(const char *className) { 00076 return demangleClassName(className, true); 00077 } 00078 00079 /** 00080 * @brief Returns an istream to read from a gzipped file (uses gzstream lib). 00081 * The stream has to be deleted after use. 00082 * @param name The name of the file to read from. 00083 * @param open_mode The mode to open the file with. Defaults to std::ios::in. 00084 * @return istream gzipped input stream from a file. 00085 */ 00086 TLP_SCOPE std::istream *getIgzstream(const std::string &name, int open_mode = std::ios::in); 00087 00088 /** 00089 * @brief Returns an ostream to write to a gzipped file (uses gzstream lib). 00090 * The stream has to be deleted after use. 00091 * @warning Don't forget to check the stream with ios::bad()! 00092 * @param name The name of the file to write to. 00093 * @param open_mode The mode to open the file with. Defaults to std::ios::out. 00094 * @return ostream gzipped output stream to a file. 00095 */ 00096 TLP_SCOPE std::ostream *getOgzstream(const std::string &name, int open_mode = std::ios::out); 00097 00098 /** 00099 * @brief give the value of the seed used for further initialization 00100 * of a random sequence (with further calls to rand() or rand_r(...)). 00101 * @param seed the value of the seed. 00102 * Set seed to UINT_MAX if you need a random choice of the seed. 00103 */ 00104 TLP_SCOPE void setSeedOfRandomSequence(unsigned int seed = UINT_MAX); 00105 00106 /** 00107 * @brief return the value of the seed used for further initialization 00108 * of a random sequence 00109 */ 00110 TLP_SCOPE unsigned int getSeedOfRandomSequence(); 00111 00112 /** 00113 * @brief initialize a random sequence with the seed previously set 00114 * Further calls to rand() or rand_r(...) will return the elements of 00115 * that sequence 00116 */ 00117 TLP_SCOPE void initRandomSequence(); 00118 00119 /** 00120 * @brief Cross-platform function to stat a path on a filesystem. Its purpose is to support 00121 * paths on windows platform containing non-ascii characters. 00122 * @param pathname an utf-8 encoded string containing the path name to stat 00123 * @param buf a pointer to a tlp_stat_t structure (a typedef for struct stat) 00124 */ 00125 TLP_SCOPE int statPath(const std::string &pathname, tlp_stat_t *buf); 00126 00127 /** 00128 * @brief Cross-platform function to get an input file stream. Its purpose is to support 00129 * paths on windows platform containing non-ascii characters. 00130 * @param filename an utf-8 encoded string containing the path of the file to open for performing input operations 00131 * @param open_mode the stream opening mode flags (bitwise combination of std::ios_base::openmode constants). 00132 */ 00133 TLP_SCOPE std::istream *getInputFileStream(const std::string &filename, std::ios_base::openmode open_mode = std::ios::in); 00134 00135 /** 00136 * @brief Cross-platform function to get an output file stream. Its purpose is to support 00137 * paths on windows platform containing non-ascii characters. 00138 * @param filename an utf-8 encoded string containing the path of the file to open for performing output operations 00139 * @param open_mode the stream opening mode flags (bitwise combination of std::ios_base::openmode constants). 00140 */ 00141 TLP_SCOPE std::ostream *getOutputFileStream(const std::string &filename, std::ios_base::openmode open_mode = std::ios::out); 00142 00143 } 00144 00145 #endif