Przeglądaj źródła

refactor & feat: 修改aFuntool::FilePath

SongZihuan 3 lat temu
rodzic
commit
121ec0d353

+ 6 - 6
include/core/code.h

@@ -8,20 +8,20 @@ namespace aFuncore {
     public:
         class ByteCode;
 
-        inline explicit Code(aFuntool::StringFilePath file_);
+        inline explicit Code(aFuntool::FilePath file_);
         ~Code();
         Code &operator=(const Code &)=delete;
 
         void display() const;
         [[nodiscard]] std::string getMD5_v1() const;
-        bool writeByteCode(aFuntool::ConstFilePath file_path, bool debug=false) const;  // NOLINT 允许忽略返回值
-        bool readByteCode(aFuntool::ConstFilePath file_path);
+        bool writeByteCode(const aFuntool::FilePath &file_path, bool debug=false) const;  // NOLINT 允许忽略返回值
+        bool readByteCode(const aFuntool::FilePath &file_path);
 
-        [[nodiscard]] inline aFuntool::ConstFilePath getFilePath() const;
+        [[nodiscard]] inline const aFuntool::FilePath &getFilePath() const;
         [[nodiscard]] inline ByteCode *getByteCode() const;
     private:
         ByteCode *code;
-        aFuntool::StringFilePath file;
+        aFuntool::FilePath file;
 
         bool write_v1(FILE *f, bool debug=false) const;
         bool read_v1(FILE *f, bool debug=false);
@@ -60,7 +60,7 @@ namespace aFuncore {
         [[nodiscard]] BlockType getBlockType() const;
         [[nodiscard]] ByteCode *getSon() const;
         [[nodiscard]] aFuntool::FileLine getFileLine() const;
-        [[nodiscard]] aFuntool::ConstFilePath getFilePath() const;
+        [[nodiscard]] const aFuntool::FilePath &getFilePath() const;
 
         [[nodiscard]] ByteCode *toNext() const;
         [[nodiscard]] ByteCode *toPrev() const;

+ 3 - 3
include/core/code.inline.h

@@ -3,7 +3,7 @@
 #include "code.h"
 
 namespace aFuncore {
-    inline Code::Code(aFuntool::StringFilePath file_) : code{new ByteCode(*this, 0)}, file{std::move(file_)} {
+    inline Code::Code(aFuntool::FilePath file_) : code{new ByteCode(*this, 0)}, file{std::move(file_)} {
 
     }
 
@@ -11,7 +11,7 @@ namespace aFuncore {
         return code;
     }
 
-    inline aFuntool::ConstFilePath Code::getFilePath() const{
+    inline const aFuntool::FilePath &Code::getFilePath() const{
         return file;
     }
 
@@ -57,7 +57,7 @@ namespace aFuncore {
         return line;
     }
 
-    inline aFuntool::ConstFilePath Code::ByteCode::getFilePath() const{
+    inline const aFuntool::FilePath &Code::ByteCode::getFilePath() const{
         return belong.getFilePath();
     }
 

+ 2 - 2
include/core/core-activation.h

@@ -37,7 +37,7 @@ namespace aFuncore {
         [[nodiscard]] inline DownMessage &getDownStream();
 
         [[nodiscard]] inline aFuntool::FileLine getFileLine() const;
-        [[nodiscard]] inline  const aFuntool::StringFilePath &getFilePath() const;
+        [[nodiscard]] inline  const aFuntool::FilePath &getFilePath() const;
 
     protected:
         Activation *prev;
@@ -47,7 +47,7 @@ namespace aFuncore {
         UpMessage up;
         DownMessage down;
 
-        aFuntool::StringFilePath path;
+        aFuntool::FilePath path;
         aFuntool::FileLine line;
 
         virtual void runCodeElement(Code::ByteCode *code);

+ 1 - 1
include/core/core-activation.inline.h

@@ -28,7 +28,7 @@ namespace aFuncore {
         return line;
     }
 
-    inline const aFuntool::StringFilePath &Activation::getFilePath() const{
+    inline const aFuntool::FilePath &Activation::getFilePath() const{
         return path;
     }
 

+ 1 - 1
include/core/msg.h

@@ -56,7 +56,7 @@ namespace aFuncore {
         std::string error_type;
         std::string error_info;
         struct TrackBack{
-            const aFuntool::StringFilePath path;
+            const aFuntool::FilePath path;
             aFuntool::FileLine line;
         };
         std::list<TrackBack> trackback;

+ 1 - 1
include/tool/log.h

@@ -54,7 +54,7 @@ namespace aFuntool {
         LogFactory(const LogFactory &)=delete;
         LogFactory &operator=(const LogFactory &)=delete;
 
-        int initLogSystem(ConstFilePath path, bool is_asyn = true);
+        int initLogSystem(const aFuntool::FilePath &path, bool is_asyn = true);
         void writeLog(LogLevel level,
                       const char *id, pid_t tid,
                       const char *ti, time_t t,

+ 1 - 1
include/tool/tool-exception.h

@@ -6,7 +6,7 @@ namespace aFuntool {
     class FileOpenException : public std::exception {
         std::string message;
     public:
-        inline explicit FileOpenException(ConstFilePath file);
+        inline explicit FileOpenException(const FilePath &file);
         inline virtual const char *what();
     };
 

+ 1 - 1
include/tool/tool-exception.inline.h

@@ -4,7 +4,7 @@
 #include "tool-exception.h"
 
 namespace aFuntool {
-    inline FileOpenException::FileOpenException(ConstFilePath file) {
+    inline FileOpenException::FileOpenException(const FilePath &file) {
         this->message = std::string("File cannot open: ") + file;
     }
 

+ 1 - 3
include/tool/tool.h

@@ -14,9 +14,7 @@ namespace aFuntool {
     static const char NUL = 0;
 
     typedef uint32_t FileLine;  // 文件行号
-    typedef char *FilePath;  // 文件路径  (用于多处内存存储场景)
-    typedef std::string StringFilePath;  // 文件路径  (用于单处内存存储场景)
-    typedef const std::string &ConstFilePath;  // 文件路径  (用于参数)
+    typedef std::string FilePath;  // 文件路径
 }
 
 #include "mem.h"

+ 2 - 2
src/core/code.cpp

@@ -200,7 +200,7 @@ RETURN:
      * @param debug
      * @return
      */
-    bool Code::writeByteCode(aFuntool::ConstFilePath file_path, bool debug) const{
+    bool Code::writeByteCode(const aFuntool::FilePath &file_path, bool debug) const{
         if (code->type != ByteCode::code_start) {
             errorLog(aFunCoreLogger, "ByteCode write all did not with `start`");
             return false;
@@ -230,7 +230,7 @@ RETURN_FALSE:
      * @param file_path
      * @return
      */
-    bool Code::readByteCode(aFuntool::ConstFilePath file_path){
+    bool Code::readByteCode(const aFuntool::FilePath &file_path){
         if (code->type != ByteCode::code_start) {
             errorLog(aFunCoreLogger, "ByteCode read all did not with `start`");
             return false;

+ 1 - 1
src/tool/log.cpp

@@ -83,7 +83,7 @@ namespace aFuntool {
  * @param is_asyn 是否启用异步
  * @return
  */
-    int LogFactory::initLogSystem(ConstFilePath path, bool is_asyn){
+    int LogFactory::initLogSystem(const aFuntool::FilePath &path, bool is_asyn){
         if (path.size() >= 218)  // 路径过长
             return 0;