Re-work types.h for the second time, this is most likely not the final version, it's difficult to figure out a solution that makes the most sense when most of the code hasn't been written/moved over yet.

Originally committed to SVN as r4468.
This commit is contained in:
Amar Takhar 2010-06-09 02:07:43 +00:00
parent 9a3e1c58f0
commit ea577f8245
5 changed files with 29 additions and 11 deletions

View File

@ -20,11 +20,11 @@
#include <stdio.h> #include <stdio.h>
#include <time.h>
#include <string.h> #include <string.h>
#include "libaegisub/log.h" #include "libaegisub/log.h"
#include "libaegisub/mutex.h" #include "libaegisub/mutex.h"
#include "libaegisub/types.h"
#include "libaegisub/util.h" #include "libaegisub/util.h"
namespace agi { namespace agi {
@ -38,7 +38,7 @@ LogSink *log = new LogSink();
const char *Severity_ID = "EAWID"; const char *Severity_ID = "EAWID";
SinkMessage::SinkMessage(const char *section, Severity severity, const char *file, SinkMessage::SinkMessage(const char *section, Severity severity, const char *file,
const char *func, int line, timeval tv): const char *func, int line, agi_timeval tv):
section(section), section(section),
severity(severity), severity(severity),
file(file), file(file),
@ -109,7 +109,7 @@ Message::Message(const char *section,
len(1024) { len(1024) {
buf = new char[len]; buf = new char[len];
msg = new std::ostrstream(buf, len); msg = new std::ostrstream(buf, len);
timeval tv; agi_timeval tv;
util::time_log(tv); util::time_log(tv);
sm = new SinkMessage(section, severity, file, func, line, tv); sm = new SinkMessage(section, severity, file, func, line, tv);
} }

View File

@ -78,7 +78,7 @@ struct SinkMessage {
/// @param line Source line /// @param line Source line
/// @param tv Log time /// @param tv Log time
SinkMessage(const char *section, Severity severity, const char *file, SinkMessage(const char *section, Severity severity, const char *file,
const char *func, int line, timeval tv); const char *func, int line, agi_timeval tv);
// Destructor // Destructor
~SinkMessage(); ~SinkMessage();
@ -88,7 +88,7 @@ struct SinkMessage {
const char *file; ///< Source file const char *file; ///< Source file
const char *func; ///< Function name const char *func; ///< Function name
int line; ///< Source line int line; ///< Source line
timeval tv; ///< Time at execution agi_timeval tv; ///< Time at execution
char *message; ///< Formatted message char *message; ///< Formatted message
size_t len; ///< Message length size_t len; ///< Message length
}; };

View File

@ -21,6 +21,15 @@
#ifndef LAGI_PRE #ifndef LAGI_PRE
#endif // LAGI_PRE #endif // LAGI_PRE
#ifdef _WIN32
#include <time.h>
#else // Unix / OSX
#include <sys/time.h>
#endif // if _WIN32
#pragma once #pragma once
namespace agi { namespace agi {
@ -61,3 +70,14 @@ typedef struct tm {
} // namespace type } // namespace type
} // namespace agi } // namespace agi
#ifdef _WIN32
typedef agi::type::win::timeval agi_timeval;
#else // Unix / OSX
typedef timeval agi_timeval;
#endif // if _WIN32

View File

@ -32,7 +32,7 @@ namespace agi {
const std::string DirName(const std::string& path); const std::string DirName(const std::string& path);
void Rename(const std::string& from, const std::string& to); void Rename(const std::string& from, const std::string& to);
void time_log(timeval &tv); void time_log(agi_timeval &tv);
} // namespace util } // namespace util
} // namespace agi } // namespace agi

View File

@ -25,13 +25,11 @@
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <time.h>
#include <windows.h> #include <windows.h>
#endif #endif
#include "libaegisub/types.h" #include "libaegisub/types.h"
#include <libaegisub/charset_conv_win.h> #include "libaegisub/charset_conv_win.h"
#include "libaegisub/util.h" #include "libaegisub/util.h"
#include "libaegisub/util_win.h" #include "libaegisub/util_win.h"
@ -74,9 +72,9 @@ std::string ErrorString(DWORD error) {
} }
/// @brief Get seconds and microseconds. /// @brief Get seconds and microseconds.
/// @param tv[out] timeval struct /// @param tv[out] agi_timeval struct
/// This code is from http://www.suacommunity.com/dictionary/gettimeofday-entry.php /// This code is from http://www.suacommunity.com/dictionary/gettimeofday-entry.php
void time_log(type::win::timeval &tv) { void time_log(agi_timeval &tv) {
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else #else