ComSDK
 Указатель Классы Пространства имен Функции Переменные Определения типов Перечисления Элементы перечислений Друзья Группы Страницы
filetools.h
1 //===========================================================================
2 #ifndef comfrm_FileWorking_stlH
3 #define comfrm_FileWorking_stlH
4 //===========================================================================
5 // Заготовка модуля FileWorking_stl была сгенерирована специальным средством RAD разработки SA2-DE.
6 // Все права защищены. (2009)
7 //
8 // В данном файле представлен исходный текст основного заголовочного файла модуля.
9 //
10 // ======================================= //
11 // Параметры новой разработки.
12 // ======================================= //
13 // Имя комплекса: CommonTools (com)
14 // Имя решения: FileTools (ftl) (прочерк если модуль относится лишь к комплексу)
15 // Имя проекта: FileWorking_stl (fil) (прочерк если модуль относится лишь к решению)
16 // Полный SID: comftlfil
17 // Время создания: 21:20:45
18 // Дата создания: 01.12.2009
19 // ======================================= //
20 // ============================================================================================ //
21 // Параметры ревизии(версии):
22 // ============================================================================================ //
23 // [prd]Period: 12/2009
24 // [aut]Author: Alexandr Sokolov
25 // [did]DeveloperID: sa
26 // [pid]ProblemID: 00001
27 // [rvs = did.date.pid]Revision: //#sa.01.12.2009.00001
28 // [dsc]Description: Функции для обработки файлов в стандарте SA2 DE.
29 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
30 // ============================================================================================ //
31 // ============================================================================================ //
32 // [prd]Period: 03/2013
33 // [aut]Author: Александр Соколов
34 // [did]DeveloperID: sa
35 // [pid]ProblemID: 00002
36 // [rvs = did.date.pid]Revision: //#sa.11.03.2013.00002
37 // [dsc]Description: Модуль StandardExt устарел и более не используется !!!
38 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
39 // ============================================================================================ //
40 // [prd]Period: 05/2013
41 // [aut]Author: Макаренков Вячеслав
42 // [did]DeveloperID: mv
43 // [pid]ProblemID: 00003
44 // [rvs = did.date.pid]Revision: //#mv.13.05.2013.00003
45 // [dsc]Description: Добавлена функция fileGetLine, читающая строку из файла любой длины
46 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
47 // ============================================================================================ //
48 // [prd]Period: 05/2013
49 // [aut]Author: Макаренков Вячеслав
50 // [did]DeveloperID: mv
51 // [pid]ProblemID: 00004
52 // [rvs = did.date.pid]Revision: //#mv.17.05.2013.00004
53 // [dsc]Description: Функция getSlash(), формирующая платформонезависимый слеш
54 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
55 // ============================================================================================ //
56 // [prd]Period: 06/2015
57 // [aut]Author: Першин Антон
58 // [did]DeveloperID: ap
59 // [pid]ProblemID: 00005
60 // [rvs = did.date.pid]Revision: //#ap.14.06.2015.00005
61 // [dsc]Description: Множество изменений, направленных на обеспечение
62 // платформонезависимого функционирования. Среди них: legacy-код работы с файлами заменен на
63 // boost-реализацию, проставлены #ifdef _WIN32 директивы для Windows-only кода. Также
64 // сделаны минорные модификации для улучшения чистоты и читаемости кода.
65 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
66 // ============================================================================================ //
67 //========================================================================
68 // A. ДОПОЛНИТЕЛЬНЫЕ ПОДКЛЮЧЕНИЯ (Типы и модули, необходимые для .h - файла)
69 //------------------------------------------------------------------------
70 #define BOOST_FILESYSTEM_NO_DEPRECATED
71 #define BOOST_FILESYSTEM_VERSION 3
72 
73 #include "stringtools.h"
74 
75 #include <string>
76 #include <stdlib.h>
77 #include <functional>
78 #include <boost/filesystem.hpp>
79 #include <boost/filesystem/path.hpp>
80 
81 #ifdef _WIN32
82 #include <windows.h>
83 #endif
84 
85 
86 namespace com
87 {
94  namespace fs
95  {
96  template<class FS>
97  int seekStreamTo(FS& p_fstream, const char* p_keyword)
98  {
99  char strbuf[100];
100  int res=-1;
101  do
102  {
103  p_fstream >> strbuf;
104  //
105  if (strstr(strbuf,p_keyword)>0)
106  {
107  res=0;
108  break;
109  }
110  }
111  while(!p_fstream.eof());
112  return res;
113  }
114 
115  #ifdef _WIN32
116 
123  MAC_DLLEXPORT std::string getCurrentModuleFullFilename(HMODULE p_module=NULL);
124 
132  MAC_DLLEXPORT std::string getCurrentModuleName(HMODULE p_module=NULL);
133  #endif
134 
140  MAC_DLLEXPORT std::string getHostModuleFullPath();
141 
146  MAC_DLLEXPORT std::string getFullPathByRelativeDir(const std::string& p_rel_dir);
147 
151  MAC_DLLEXPORT std::string getPluginsFullPath();
152 
156  MAC_DLLEXPORT std::string getPythonScriptsFullPath();
157 
161  MAC_DLLEXPORT std::string getExternalBinariesFullPath();
162 
168  MAC_DLLEXPORT std::string getFullPath(const std::string& p_relative_path, const std::string& p_filename="");
169 
173  MAC_DLLEXPORT std::string getCFGFullPath();
174 
178  MAC_DLLEXPORT std::string getXMLFullPath();
179 
186  MAC_DLLEXPORT std::string getStrFormatedCode(int p_id, int p_format_length);
187 
191  MAC_DLLEXPORT bool fileExists(const std::string& p_fullFilename);
192 
196  MAC_DLLEXPORT bool libExists(const std::string& p_fullLibPath);
197 
207  MAC_DLLEXPORT std::string createResultFilename(const std::string& p_name,
208  char p_separator,
209  int p_not_existent_id,
210  int p_digits,
211  const std::string& p_extension);
212 
216  MAC_DLLEXPORT std::string getPathWOFilename(const std::string& p_path);
217 
221  MAC_DLLEXPORT std::string getFilenameWOPath(const std::string& p_path);
222 
226  MAC_DLLEXPORT std::string getFileExtension(const std::string& p_filename);
227 
231  MAC_DLLEXPORT std::string getFilenameWOExtension(const std::string& p_filename);
232 
236  MAC_DLLEXPORT bool fileGetLine(std::ifstream& is, std::string& line);
237 
242  MAC_DLLEXPORT std::string slash();
243 
248  MAC_DLLEXPORT std::string nativeSlash();
249 
255  MAC_DLLEXPORT std::string toNativeSlash(const std::string& p_path );
256 
257  // Вспомогательные предикаты
258  class FilenameEqual: public std::unary_function< boost::filesystem::path, bool >
259  {
260  public:
261  explicit FilenameEqual(const boost::filesystem::path& fname): mFilename(fname) { }
262 
263  bool operator()(const boost::filesystem::directory_entry& entry) const
264  {
265  return entry.path().filename() == mFilename;
266  }
267 
268  private:
269  boost::filesystem::path mFilename;
270  };
271  }
272 }
273 
274 //===========================================================================
275 #endif // unt_FileWorking_stlH
276 //===========================================================================
MAC_DLLEXPORT std::string getFileExtension(const std::string &p_filename)
MAC_DLLEXPORT std::string getFilenameWOPath(const std::string &p_path)
Definition: filetools.cpp:159
Definition: filetools.h:258
MAC_DLLEXPORT std::string getPluginsFullPath()
Definition: filetools.cpp:262
MAC_DLLEXPORT std::string getFullPathByRelativeDir(const std::string &p_rel_dir)
MAC_DLLEXPORT std::string getXMLFullPath()
Definition: filetools.cpp:349
MAC_DLLEXPORT bool libExists(const std::string &p_fullLibPath)
Definition: filetools.cpp:361
MAC_DLLEXPORT std::string getPythonScriptsFullPath()
Definition: filetools.cpp:268
MAC_DLLEXPORT bool fileGetLine(std::ifstream &is, std::string &line)
Definition: filetools.cpp:391
MAC_DLLEXPORT std::string toNativeSlash(const std::string &p_path)
Definition: filetools.cpp:433
MAC_DLLEXPORT std::string getHostModuleFullPath()
Definition: filetools.cpp:181
MAC_DLLEXPORT std::string createResultFilename(const std::string &p_name, char p_separator, int p_not_existent_id, int p_digits, const std::string &p_extension)
MAC_DLLEXPORT std::string getExternalBinariesFullPath()
Definition: filetools.cpp:274
MAC_DLLEXPORT std::string getPathWOFilename(const std::string &p_path)
MAC_DLLEXPORT std::string getStrFormatedCode(int p_id, int p_format_length)
Definition: filetools.cpp:228
MAC_DLLEXPORT std::string slash()
Definition: filetools.cpp:417
MAC_DLLEXPORT std::string getFilenameWOExtension(const std::string &p_filename)
MAC_DLLEXPORT std::string getCFGFullPath()
Definition: filetools.cpp:343
MAC_DLLEXPORT std::string nativeSlash()
Definition: filetools.cpp:423
MAC_DLLEXPORT bool fileExists(const std::string &p_fullFilename)
MAC_DLLEXPORT std::string getFullPath(const std::string &p_relative_path, const std::string &p_filename="")