Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
7f8fb838
Commit
7f8fb838
authored
Jun 11, 2016
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add win32.h
parent
37046691
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
61 deletions
+108
-61
Log.h
Log.h
+23
-22
global.h
global.h
+1
-39
win32.h
win32.h
+84
-0
No files found.
Log.h
View file @
7f8fb838
...
...
@@ -26,6 +26,7 @@ or else it might cause multiple constructions.
#include <boost/noncopyable.hpp>
#include "utf8.h"
#include "chrono_wrapper.h"
#include "singleton.h"
namespace
jlib
{
...
...
@@ -36,9 +37,9 @@ namespace jlib
#define JLOGB(b, l) jlib::log::dump_hex(b, l)
#define JLOGASC(b, l) jlib::log::dump_ascii(b, l)
#define IMPLEMENT_CLASS_LOG_STATIC_MEMBER jlib::log* jlib::log::instance_ = nullptr;
//
#define IMPLEMENT_CLASS_LOG_STATIC_MEMBER jlib::log* jlib::log::instance_ = nullptr;
class
log
:
p
rivate
boost
::
noncopyable
class
log
:
p
ublic
dp
::
singleton
<
log
>
{
enum
{
max_output_size
=
1024
*
64
,
max_single_log_file_size
=
1024
*
1024
*
10
};
...
...
@@ -52,7 +53,7 @@ private:
std
::
string
log_file_path_
=
""
;
std
::
string
line_prefix_
=
""
;
std
::
mutex
lock_
;
static
log
*
instance_
;
//
static log* instance_;
public
:
// initializers, they should be called right after get_instance
...
...
@@ -70,20 +71,20 @@ public:
public
:
static
log
*
get_instance
()
{
/*
Warnning:
The singleton pattern that log implemented is not thread-safe,
you should call log::get_instance() once in your main thread,
or else it might cause multiple constructions.
*/
if
(
log
::
instance_
==
nullptr
)
{
static
log
log_
;
log
::
instance_
=
&
log_
;
}
return
log
::
instance_
;
}
//
static log* get_instance()
//
{
//
/*
//
Warnning:
//
The singleton pattern that log implemented is not thread-safe,
//
you should call log::get_instance() once in your main thread,
//
or else it might cause multiple constructions.
//
*/
//
if (log::instance_ == nullptr) {
//
static log log_;
//
log::instance_ = &log_;
//
}
//
return log::instance_;
//
}
~
log
()
{
...
...
@@ -105,7 +106,7 @@ public:
static
void
dump_hex
(
const
char
*
buff
,
size_t
buff_len
)
{
try
{
log
*
instance
=
log
::
get_instance
();
auto
instance
=
log
::
get_instance
();
if
(
instance
->
log_to_file_
||
instance
->
log_to_dbg_view_
||
instance
->
log_to_console_
)
{
size_t
output_len
=
buff_len
*
6
+
64
;
...
...
@@ -132,7 +133,7 @@ public:
static
void
dump_ascii
(
const
char
*
buff
,
size_t
buff_len
)
{
try
{
log
*
instance
=
log
::
get_instance
();
auto
instance
=
log
::
get_instance
();
if
(
instance
->
log_to_file_
||
instance
->
log_to_dbg_view_
||
instance
->
log_to_console_
)
{
size_t
output_len
=
buff_len
*
6
+
64
;
...
...
@@ -159,7 +160,7 @@ public:
static
void
log_utf16
(
const
wchar_t
*
format
,
...)
{
try
{
log
*
instance
=
log
::
get_instance
();
auto
instance
=
log
::
get_instance
();
if
(
instance
->
log_to_file_
||
instance
->
log_to_dbg_view_
||
instance
->
log_to_console_
)
{
wchar_t
buf
[
max_output_size
],
*
p
;
...
...
@@ -201,7 +202,7 @@ public:
static
void
log_utf8
(
const
char
*
format
,
...)
{
try
{
log
*
instance
=
log
::
get_instance
();
auto
instance
=
log
::
get_instance
();
if
(
instance
->
log_to_file_
||
instance
->
log_to_dbg_view_
||
instance
->
log_to_console_
)
{
char
buf
[
max_output_size
],
*
p
;
...
...
@@ -216,7 +217,7 @@ public:
*
p
++
=
'\n'
;
*
p
=
'\0'
;
instance
_
->
output
(
instance
->
format_msg
(
buf
));
instance
->
output
(
instance
->
format_msg
(
buf
));
}
}
catch
(...)
{
assert
(
0
);
...
...
global.h
View file @
7f8fb838
...
...
@@ -12,45 +12,7 @@
#include "micro_getter_setter.h"
//#include "micro_singleton.h"
#include "singleton.h"
#include "win32.h"
namespace
jlib
{
inline
std
::
wstring
get_exe_path
()
{
wchar_t
path
[
1024
]
=
{
0
};
GetModuleFileName
(
nullptr
,
path
,
1024
);
std
::
wstring
::
size_type
pos
=
std
::
wstring
(
path
).
find_last_of
(
L"
\\
/"
);
return
std
::
wstring
(
path
).
substr
(
0
,
pos
);
}
inline
std
::
string
get_exe_path_a
()
{
char
path
[
1024
]
=
{
0
};
GetModuleFileNameA
(
nullptr
,
path
,
1024
);
std
::
string
::
size_type
pos
=
std
::
string
(
path
).
find_last_of
(
"
\\
/"
);
return
std
::
string
(
path
).
substr
(
0
,
pos
);
}
class
auto_timer
:
public
boost
::
noncopyable
{
private
:
int
m_timer_id
;
DWORD
m_time_out
;
HWND
m_hWnd
;
public
:
auto_timer
(
HWND
hWnd
,
int
timerId
,
DWORD
timeout
)
:
m_hWnd
(
hWnd
),
m_timer_id
(
timerId
),
m_time_out
(
timeout
)
{
KillTimer
(
hWnd
,
m_timer_id
);
}
~
auto_timer
()
{
SetTimer
(
m_hWnd
,
m_timer_id
,
m_time_out
,
nullptr
);
}
};
};
win32.h
0 → 100644
View file @
7f8fb838
#pragma once
#include <windows.h>
#include <string>
namespace
jlib
{
inline
std
::
wstring
get_exe_path
()
{
wchar_t
path
[
1024
]
=
{
0
};
GetModuleFileName
(
nullptr
,
path
,
1024
);
std
::
wstring
::
size_type
pos
=
std
::
wstring
(
path
).
find_last_of
(
L"
\\
/"
);
return
std
::
wstring
(
path
).
substr
(
0
,
pos
);
}
inline
std
::
string
get_exe_path_a
()
{
char
path
[
1024
]
=
{
0
};
GetModuleFileNameA
(
nullptr
,
path
,
1024
);
std
::
string
::
size_type
pos
=
std
::
string
(
path
).
find_last_of
(
"
\\
/"
);
return
std
::
string
(
path
).
substr
(
0
,
pos
);
}
inline
BOOL
Win32CenterWindow
(
HWND
hwndWindow
)
{
HWND
hwndParent
;
RECT
rectWindow
,
rectParent
;
if
((
hwndParent
=
GetParent
(
hwndWindow
))
==
NULL
)
{
hwndParent
=
GetDesktopWindow
();
}
// make the window relative to its parent
if
(
hwndParent
!=
NULL
)
{
GetWindowRect
(
hwndWindow
,
&
rectWindow
);
GetWindowRect
(
hwndParent
,
&
rectParent
);
int
nWidth
=
rectWindow
.
right
-
rectWindow
.
left
;
int
nHeight
=
rectWindow
.
bottom
-
rectWindow
.
top
;
int
nX
=
((
rectParent
.
right
-
rectParent
.
left
)
-
nWidth
)
/
2
+
rectParent
.
left
;
int
nY
=
((
rectParent
.
bottom
-
rectParent
.
top
)
-
nHeight
)
/
2
+
rectParent
.
top
;
int
nScreenWidth
=
GetSystemMetrics
(
SM_CXSCREEN
);
int
nScreenHeight
=
GetSystemMetrics
(
SM_CYSCREEN
);
// make sure that the dialog box never moves outside of the screen
if
(
nX
<
0
)
nX
=
0
;
if
(
nY
<
0
)
nY
=
0
;
if
(
nX
+
nWidth
>
nScreenWidth
)
nX
=
nScreenWidth
-
nWidth
;
if
(
nY
+
nHeight
>
nScreenHeight
)
nY
=
nScreenHeight
-
nHeight
;
MoveWindow
(
hwndWindow
,
nX
,
nY
,
nWidth
,
nHeight
,
FALSE
);
return
TRUE
;
}
return
FALSE
;
}
class
auto_timer
:
public
boost
::
noncopyable
{
private
:
int
m_timer_id
;
DWORD
m_time_out
;
HWND
m_hWnd
;
public
:
auto_timer
(
HWND
hWnd
,
int
timerId
,
DWORD
timeout
)
:
m_hWnd
(
hWnd
),
m_timer_id
(
timerId
),
m_time_out
(
timeout
)
{
KillTimer
(
hWnd
,
m_timer_id
);
}
~
auto_timer
()
{
SetTimer
(
m_hWnd
,
m_timer_id
,
m_time_out
,
nullptr
);
}
};
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment