Kaynağa Gözat

add hfile iniparser

ithewei 7 yıl önce
ebeveyn
işleme
42edd16c3e
4 değiştirilmiş dosya ile 19 ekleme ve 24 silme
  1. 4 3
      hfile.h
  2. 5 2
      hframe.h
  3. 8 0
      hmutex.h
  4. 2 19
      iniparser.cpp

+ 4 - 3
hfile.h

@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
 #include <sys/stat.h>
 
 #include "hdef.h"
@@ -38,9 +39,9 @@ public:
     }
 
     size_t size() {
-        struct _stat stat;
-        _stat(_filepath, &stat);
-        return stat.st_size;       
+        struct stat st;
+        stat(_filepath, &st);
+        return st.st_size;     
     }
 
     size_t read(void* ptr, size_t len) {

+ 5 - 2
hframe.h

@@ -1,9 +1,11 @@
 #ifndef H_FRAME_H
 #define H_FRAME_H
 
-#include "hbuf.h"
 #include <deque>
 
+#include "hbuf.h"
+#include "hmutex.h"
+
 typedef struct hframe_s{
     hbuf_t buf;
     int w;
@@ -57,7 +59,7 @@ typedef struct frame_stats_s{
 
 #define DEFAULT_FRAME_CACHENUM  10
 
-class HFrameBuf : public HRingBuf{
+class HFrameBuf : public HRingBuf {
 public:
     enum CacheFullPolicy{
         SQUEEZE,
@@ -79,6 +81,7 @@ public:
     FrameStats  frame_stats;
     FrameInfo   frame_info;
     std::deque<HFrame> frames;
+    std::mutex         mutex;
 };
 
 #endif // H_FRAME_H

+ 8 - 0
hmutex.h

@@ -1,8 +1,15 @@
 #ifndef H_MUTEX_H
 #define H_MUTEX_H
 
+#include <mutex>
+
 #include "hplatform.h"
 
+class HMutex {
+protected:
+    std::mutex  _mutex;
+};
+
 #ifdef _MSC_VER
 class RWLock{
 public:
@@ -17,6 +24,7 @@ public:
 private:
     SRWLOCK _rwlock;
 };
+};
 #else
 class RWLock{
 public:

+ 2 - 19
iniparser.cpp

@@ -6,7 +6,6 @@
 
 #include <sstream>
 
-#include "hlog.h"
 #include "herr.h"
 #include "hfile.h"
 
@@ -30,29 +29,15 @@ int IniParser::LoadFromFile(const char* filepath) {
 
     HFile file;
     if (file.open(filepath, "r") != 0) {
-        hloge("Open file [%s] failed!", filepath);
         return ERR_OPEN_FILE;
     }
 
     hbuf_t buf;
     file.readall(buf);
-    hlogi("filesize=%d", buf.len);
-    hlogi("%s", buf.base);
 
     return LoadFromMem((const char*)buf.base);
 }
 
-/********************************************
-# test.ini
-# this is a test ini file.
-
-[section] # tail_comment
-# key
-key = value # tail_comment
-
-# other
-# end
-********************************************/
 int IniParser::LoadFromMem(const char* data) {
     Unload();
 
@@ -86,7 +71,6 @@ int IniParser::LoadFromMem(const char* data) {
         if (pos != string::npos) {
             comment = content.substr(pos);
             content = content.substr(0, pos);
-            hlogi("pos=%d content=%s comment=%s", pos, content.c_str(), comment.c_str());
         }
 
         content = trimR(content);
@@ -112,7 +96,7 @@ int IniParser::LoadFromMem(const char* data) {
                 root_->Add(pNewNode);
                 pScopeNode = pNewNode;
             } else {
-                hlogw("format error, line:%d", line);
+                // hlogw("format error, line:%d", line);
                 continue;   // ignore    
             }
         } else {
@@ -125,7 +109,7 @@ int IniParser::LoadFromMem(const char* data) {
                 pNewNode->value = trim(content.substr(pos+_delim.length()));
                 pScopeNode->Add(pNewNode);
             } else {
-                hlogw("format error, line:%d", line);
+                // hlogw("format error, line:%d", line);
                 continue;   // ignore
             }
         }
@@ -207,7 +191,6 @@ int IniParser::SaveAs(const char* filepath) {
 
     HFile file;
     if (file.open(filepath, "w") != 0) {
-        hloge("Save file [%s] failed.", filepath);
         return ERR_SAVE_FILE;
     }
     file.write(str.c_str(), str.length());