BIMHome v1.0.0
BIMHome接口文档说明
FileInfo.h
浏览该文件的文档.
1/************************************************************************
2* @file FileInfo.h
3*
4* @brief
5*
6* @details
7*
8* @author wukx
9*
10* @version v1.0
11*
12* @date 2016.9.29
13*
14* @license 北京华科软科技有限公司
15*
16*************************************************************************/
17
18#ifndef BIMHOMEBASE_FILEINFO_H
19#define BIMHOMEBASE_FILEINFO_H
20
21#include <boost/filesystem.hpp>
22#include <string>
23#include <vector>
24#include <Base/TimeInfo.h>
25#include <QString>
26#include "QMap"
27
28
29namespace Base
30{
31
37 class BaseExport FileInfo
38 {
39 public:
41 {
42 WriteOnly = 0x01,
43 ReadOnly = 0x02,
44 ReadWrite = 0x03,
45 };
47 QString sWord;
50 double sFontWidth;
52 sWord = QString::fromLocal8Bit("");
53 sFontHeight = 0.0;
54 sWidthFactor = 0.0;
55 sFontWidth = 0.0;
56 }
57 };
58 typedef QMap<QString, FontCalculate> FontInfoVec;
60 FileInfo(const char* _FileName = "");
61 FileInfo(const std::string& _FileName);
63 void setFile(const char* name);
65 void setFile(const std::string& name) { setFile(name.c_str()); }
66
67
71 std::string filePath() const;
73 std::string dirPath() const;
75 std::string fileName() const;
77 std::string fileNamePure() const;
80 std::wstring toStdWString() const;
89 std::string extension() const;
98 std::string completeExtension() const;
100 bool hasExtension(const char* Ext) const;
102
106 bool exists() const;
108 bool isReadable() const;
110 bool isWritable() const;
114 bool isFile() const;
116 bool isDir() const;
118 unsigned int size() const;
124
128 bool createDirectory() const;
130 bool createDirectories() const;
132 std::vector<Base::FileInfo> getDirectoryContent() const;
134 bool deleteDirectory() const;
138
140 bool deleteFile() const;
142 bool renameFile(const char* NewName);
144 bool copyTo(const char* NewName) const;
145
149 static std::string getTempFileName(const char* FileName=nullptr, const char* path=nullptr);
151 static const std::string &getTempPath();
153 static std::string pathToString(const boost::filesystem::path& p);
155 static boost::filesystem::path stringToPath(const std::string& str);
157public:
158 static std::string ConvertFromWideString(const std::wstring& string);
159 static std::wstring ConvertToWideString(const std::string& string);
160 static void unicodeToUTF8(const std::wstring& src, std::string& result);
161 static void gb2312ToUnicode(const std::string& src, std::wstring& result);
162 static std::string GbkToUtf8(std::string str);
163 static void gb2312ToUtf8(const std::string& src, std::string& result);
164 static std::string gb2312ToUtf8(const std::string& src);
165 static std::wstring string2wstring(std::string str);
166 static std::string wstring2string(std::wstring wstr);
167 static void utf8ToGB2312(const char* utf8, char*& gb2312);
168 //
169 static bool isLetter(const QString& str);
170 static bool isDigit(const QString& str);
171 static bool isSymbol(const QString& str);
172 static bool isChinese(const QString& str);
173 //
174 static FontInfoVec getFontFileInfo(const QString& fontFamily);
175 //获得文字宽度
176 static double getNormalFontWidth(const QString& fontFamily, const QString& text, double fontheight, double widthFactor);
177 static double getFontWidth(const QString& fontFamily, const QString& text, double fontheight, double widthFactor);
178 //文本信息参数值解析
179 static bool calcExpress(const std::string& sExpress, const std::map<std::string, double>& paramMap, double& dValue);
180
181 // 删除列表中距离为0的数据
182 static void eraseVectorMinDistance(std::vector<double>& vec, const double& error);
183
184protected:
185 std::string FileName;
186};
187
188} //namespace Base
189
190
191#endif // BIMHOMEBASE_FILEINFO_H
static void gb2312ToUtf8(const std::string &src, std::string &result)
bool renameFile(const char *NewName)
Rename the file
std::string completeExtension() const
Returns the complete extension of the file.
static boost::filesystem::path stringToPath(const std::string &str)
Convert from string to filesystem path
std::string FileName
Definition FileInfo.h:185
static bool calcExpress(const std::string &sExpress, const std::map< std::string, double > &paramMap, double &dValue)
std::string extension() const
Returns the extension of the file.
bool createDirectories() const
Creates a directory and all its parent directories. Returns true if successful; otherwise returns fal...
std::string dirPath() const
Returns the dir path name (which may be absolute or relative).
void setFile(const std::string &name)
Set a new file name
Definition FileInfo.h:65
static std::string ConvertFromWideString(const std::wstring &string)
std::string fileName() const
Returns the name of the file, excluding the path, including the extension.
bool isFile() const
Checks if it is a file (not a directory)
static bool isDigit(const QString &str)
bool hasExtension(const char *Ext) const
Checks for a special extension, NOT case sensitive
static std::string wstring2string(std::wstring wstr)
static void gb2312ToUnicode(const std::string &src, std::wstring &result)
Permissions
Definition FileInfo.h:41
unsigned int size() const
The size of the file
std::string filePath() const
Returns the file name, including the path (which may be absolute or relative).
FileInfo(const std::string &_FileName)
static std::string getTempFileName(const char *FileName=nullptr, const char *path=nullptr)
Get a unique File Name in the given or (if 0) in the temp path
static std::wstring string2wstring(std::string str)
bool createDirectory() const
Creates a directory. Returns true if successful; otherwise returns false.
bool deleteFile() const
Delete the file
FileInfo(const char *_FileName="")
Construction
static bool isLetter(const QString &str)
bool isWritable() const
Checks if the file exist and is writable
void setFile(const char *name)
Set a new file name
static std::string pathToString(const boost::filesystem::path &p)
Convert from filesystem path to string
TimeInfo lastRead() const
Returns the time when the file was last read (accessed).
static bool isSymbol(const QString &str)
static FontInfoVec getFontFileInfo(const QString &fontFamily)
static void utf8ToGB2312(const char *utf8, char *&gb2312)
static const std::string & getTempPath()
Get the path to the dir which is considered to temp files
bool exists() const
Does the file exist?
static void eraseVectorMinDistance(std::vector< double > &vec, const double &error)
TimeInfo lastModified() const
Returns the time when the file was last modified.
static void unicodeToUTF8(const std::wstring &src, std::string &result)
QMap< QString, FontCalculate > FontInfoVec
Definition FileInfo.h:58
static std::string GbkToUtf8(std::string str)
static bool isChinese(const QString &str)
bool copyTo(const char *NewName) const
Rename the file
static double getNormalFontWidth(const QString &fontFamily, const QString &text, double fontheight, double widthFactor)
bool isDir() const
Checks if it is a directory (not a file)
static double getFontWidth(const QString &fontFamily, const QString &text, double fontheight, double widthFactor)
std::vector< Base::FileInfo > getDirectoryContent() const
Get a list of the directory content
bool setPermissions(Permissions)
Tries to set the file permission
bool isReadable() const
Checks if the file exist and is readable
static std::string gb2312ToUtf8(const std::string &src)
std::wstring toStdWString() const
Convert the path name into a UTF-16 encoded wide string format.
static std::wstring ConvertToWideString(const std::string &string)
std::string fileNamePure() const
Returns the name of the file, excluding the path and the extension.
bool deleteDirectoryRecursive() const
Delete a directory and all its content.
bool deleteDirectory() const
Delete an empty directory
File name unification This class handles everything related to file names the file names are internal...
Definition FileInfo.h:38
TimeInfo 类,用于表示时间信息
Definition TimeInfo.h:36
Definition BaseFigureFactory.h:24
double sFontHeight
Definition FileInfo.h:48
double sWidthFactor
Definition FileInfo.h:49
FontCalculate()
Definition FileInfo.h:51
double sFontWidth
Definition FileInfo.h:50
QString sWord
Definition FileInfo.h:47
Definition FileInfo.h:46