You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by dx...@apache.org on 2017/05/22 17:43:12 UTC

[trafficserver] branch master updated: Clean up BaseLogFile

This is an automated email from the ASF dual-hosted git repository.

dxu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  b817429   Clean up BaseLogFile
b817429 is described below

commit b8174292e7849f23f0f7b36cc917e95ab667a39f
Author: Daniel Xu <dx...@dxuuu.xyz>
AuthorDate: Fri May 5 10:59:15 2017 -0500

    Clean up BaseLogFile
    
    Let's use some C++11 features!
---
 lib/ts/BaseLogFile.cc | 29 +++++------------------------
 lib/ts/BaseLogFile.h  | 25 +++++++++++--------------
 2 files changed, 16 insertions(+), 38 deletions(-)

diff --git a/lib/ts/BaseLogFile.cc b/lib/ts/BaseLogFile.cc
index af5fc18..c9bbe79 100644
--- a/lib/ts/BaseLogFile.cc
+++ b/lib/ts/BaseLogFile.cc
@@ -27,9 +27,8 @@
  * This consturctor creates a BaseLogFile based on a given name.
  * This is the most common way BaseLogFiles are created.
  */
-BaseLogFile::BaseLogFile(const char *name) : m_signature(0), m_has_signature(false)
+BaseLogFile::BaseLogFile(const char *name) : m_name(ats_strdup(name))
 {
-  init(name);
   log_log_trace("exiting BaseLogFile constructor, m_name=%s, this=%p\n", m_name.get(), this);
 }
 
@@ -37,9 +36,8 @@ BaseLogFile::BaseLogFile(const char *name) : m_signature(0), m_has_signature(fal
  * This consturctor creates a BaseLogFile based on a given name.
  * Similar to above constructor, but is overloaded with the object signature
  */
-BaseLogFile::BaseLogFile(const char *name, uint64_t sig) : m_signature(sig), m_has_signature(true)
+BaseLogFile::BaseLogFile(const char *name, uint64_t sig) : m_name(ats_strdup(name)), m_signature(sig), m_has_signature(true)
 {
-  init(name);
   log_log_trace("exiting BaseLogFile signature constructor, m_name=%s, m_signature=%ld, this=%p\n", m_name.get(), m_signature,
                 this);
 }
@@ -52,13 +50,13 @@ BaseLogFile::BaseLogFile(const BaseLogFile &copy)
     m_start_time(copy.m_start_time),
     m_end_time(0L),
     m_bytes_written(0),
-    m_signature(copy.m_signature),
-    m_has_signature(copy.m_has_signature),
     m_name(ats_strdup(copy.m_name)),
     m_hostname(ats_strdup(copy.m_hostname)),
     m_is_regfile(false),
     m_is_init(copy.m_is_init),
-    m_meta_info(nullptr)
+    m_meta_info(nullptr),
+    m_signature(copy.m_signature),
+    m_has_signature(copy.m_has_signature)
 {
   log_log_trace("exiting BaseLogFile copy constructor, m_name=%s, this=%p\n", m_name.get(), this);
 }
@@ -79,23 +77,6 @@ BaseLogFile::~BaseLogFile()
 }
 
 /*
- * Initializes the defaults of some of the common member values of this class
- */
-void
-BaseLogFile::init(const char *name)
-{
-  m_fp            = nullptr;
-  m_start_time    = time(nullptr);
-  m_end_time      = 0L;
-  m_bytes_written = 0;
-  m_name          = ats_strdup(name);
-  m_hostname      = nullptr;
-  m_is_regfile    = false;
-  m_is_init       = false;
-  m_meta_info     = nullptr;
-}
-
-/*
  * This function is called by a client of BaseLogFile to roll the underlying
  * file  The tricky part to this routine is in coming up with the new file name,
  * which contains the bounding timestamp interval for the entries
diff --git a/lib/ts/BaseLogFile.h b/lib/ts/BaseLogFile.h
index 9068e5a..3c5a570 100644
--- a/lib/ts/BaseLogFile.h
+++ b/lib/ts/BaseLogFile.h
@@ -166,6 +166,8 @@ class BaseLogFile
 {
 public:
   // member functions
+  BaseLogFile()        = delete;
+  BaseLogFile &operator=(const BaseLogFile &) = delete;
   BaseLogFile(const char *name);
   BaseLogFile(const char *name, uint64_t sig);
   BaseLogFile(const BaseLogFile &);
@@ -217,27 +219,22 @@ public:
     LOG_FILE_COULD_NOT_OPEN_FILE,
   };
 
-  FILE *m_fp;
-  long m_start_time;
-  long m_end_time;
-  volatile uint64_t m_bytes_written;
+  FILE *m_fp                        = nullptr;
+  long m_start_time                 = time(nullptr);
+  long m_end_time                   = 0L;
+  volatile uint64_t m_bytes_written = 0;
 
 private:
-  void init(const char *name);
-  // member functions not allowed
-  BaseLogFile();
-  BaseLogFile &operator=(const BaseLogFile &);
-
   // member functions
   int timestamp_to_str(long timestamp, char *buf, int size);
 
   // member variables
-  uint64_t m_signature;
-  bool m_has_signature;
   ats_scoped_str m_name;
   ats_scoped_str m_hostname;
-  bool m_is_regfile;
-  bool m_is_init;
-  BaseMetaInfo *m_meta_info;
+  bool m_is_regfile         = false;
+  bool m_is_init            = false;
+  BaseMetaInfo *m_meta_info = nullptr;
+  uint64_t m_signature      = 0;
+  bool m_has_signature      = false;
 };
 #endif

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].