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
bfc76fba
Commit
bfc76fba
authored
Dec 16, 2019
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utf8
parent
3d92e869
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
37 additions
and
87 deletions
+37
-87
cast.h
jlib/base/cast.h
+1
-1
config.h
jlib/base/config.h
+1
-1
copyable.h
jlib/base/copyable.h
+1
-1
currentthread.h
jlib/base/currentthread.h
+1
-1
date.h
jlib/base/date.h
+1
-1
logging.h
jlib/base/logging.h
+1
-1
logstream.h
jlib/base/logstream.h
+1
-1
noncopyable.h
jlib/base/noncopyable.h
+1
-1
singleton.h
jlib/base/singleton.h
+1
-1
stringpiece.h
jlib/base/stringpiece.h
+17
-65
thread.h
jlib/base/thread.h
+2
-0
time.h
jlib/base/time.h
+1
-1
timezone.h
jlib/base/timezone.h
+1
-1
micro_getter_setter.h
jlib/util/micro_getter_setter.h
+2
-2
space.h
jlib/util/space.h
+3
-8
version.h
jlib/util/version.h
+1
-1
test.sln
test/test.sln
+1
-0
No files found.
jlib/base/cast.h
View file @
bfc76fba
#pragma once
#
pragma
once
namespace
jlib
{
...
...
jlib/base/config.h
View file @
bfc76fba
#pragma once
#
pragma
once
#ifdef __GNUG__
...
...
jlib/base/copyable.h
View file @
bfc76fba
#pragma once
#
pragma
once
namespace
jlib
{
...
...
jlib/base/currentthread.h
View file @
bfc76fba
#pragma once
#
pragma
once
#include "config.h"
#include <inttypes.h>
...
...
jlib/base/date.h
View file @
bfc76fba
#pragma once
#
pragma
once
#include "config.h"
#include "../3rdparty/date/include/date/date.h"
...
...
jlib/base/logging.h
View file @
bfc76fba
#pragma once
#
pragma
once
#include "config.h"
#include "logstream.h"
...
...
jlib/base/logstream.h
View file @
bfc76fba
#pragma once
#
pragma
once
#include "config.h"
#include "noncopyable.h"
...
...
jlib/base/noncopyable.h
View file @
bfc76fba
#pragma once
#
pragma
once
namespace
jlib
{
...
...
jlib/base/singleton.h
View file @
bfc76fba
#pragma once
#
pragma
once
#include "noncopyable.h"
#include <mutex>
...
...
jlib/base/stringpiece.h
View file @
bfc76fba
...
...
@@ -47,12 +47,10 @@ namespace jlib
class
StringArg
// copyable
{
public
:
StringArg
(
const
char
*
str
)
:
str_
(
str
)
StringArg
(
const
char
*
str
)
:
str_
(
str
)
{}
StringArg
(
const
std
::
string
&
str
)
:
str_
(
str
.
c_str
())
StringArg
(
const
std
::
string
&
str
)
:
str_
(
str
.
c_str
())
{}
const
char
*
c_str
()
const
{
return
str_
;
}
...
...
@@ -72,25 +70,19 @@ public:
// We provide non-explicit singleton constructors so users can pass
// in a "const char*" or a "string" wherever a "StringPiece" is
// expected.
StringPiece
()
:
ptr_
(
nullptr
),
length_
(
0
)
StringPiece
()
:
ptr_
(
nullptr
),
length_
(
0
)
{}
StringPiece
(
const
char
*
str
)
:
ptr_
(
str
),
length_
(
static_cast
<
int
>
(
strlen
(
ptr_
)))
StringPiece
(
const
char
*
str
)
:
ptr_
(
str
),
length_
(
static_cast
<
int
>
(
strlen
(
ptr_
)))
{}
StringPiece
(
const
unsigned
char
*
str
)
:
ptr_
(
reinterpret_cast
<
const
char
*>
(
str
)),
length_
(
static_cast
<
int
>
(
strlen
(
ptr_
)))
StringPiece
(
const
unsigned
char
*
str
)
:
ptr_
(
reinterpret_cast
<
const
char
*>
(
str
)),
length_
(
static_cast
<
int
>
(
strlen
(
ptr_
)))
{}
StringPiece
(
const
std
::
string
&
str
)
:
ptr_
(
str
.
data
()),
length_
(
static_cast
<
int
>
(
str
.
size
()))
StringPiece
(
const
std
::
string
&
str
)
:
ptr_
(
str
.
data
()),
length_
(
static_cast
<
int
>
(
str
.
size
()))
{}
StringPiece
(
const
char
*
offset
,
int
len
)
:
ptr_
(
offset
),
length_
(
len
)
StringPiece
(
const
char
*
offset
,
int
len
)
:
ptr_
(
offset
),
length_
(
len
)
{}
// data() may return a pointer to a buffer with embedded NULs, and the
...
...
@@ -100,54 +92,19 @@ public:
// this. Or better yet, change your routine so it does not rely on NUL
// termination.
const
char
*
data
()
const
{
return
ptr_
;
}
int
size
()
const
{
return
length_
;
}
bool
empty
()
const
{
return
length_
==
0
;
}
const
char
*
begin
()
const
{
return
ptr_
;
}
const
char
*
end
()
const
{
return
ptr_
+
length_
;
}
void
clear
()
{
ptr_
=
NULL
;
length_
=
0
;
}
void
set
(
const
char
*
buffer
,
int
len
)
{
ptr_
=
buffer
;
length_
=
len
;
}
void
set
(
const
char
*
str
)
{
ptr_
=
str
;
length_
=
static_cast
<
int
>
(
strlen
(
str
));
}
void
set
(
const
void
*
buffer
,
int
len
)
{
ptr_
=
reinterpret_cast
<
const
char
*>
(
buffer
);
length_
=
len
;
}
void
clear
()
{
ptr_
=
NULL
;
length_
=
0
;
}
void
set
(
const
char
*
buffer
,
int
len
)
{
ptr_
=
buffer
;
length_
=
len
;
}
void
set
(
const
char
*
str
)
{
ptr_
=
str
;
length_
=
static_cast
<
int
>
(
strlen
(
str
));
}
void
set
(
const
void
*
buffer
,
int
len
)
{
ptr_
=
reinterpret_cast
<
const
char
*>
(
buffer
);
length_
=
len
;
}
char
operator
[](
int
i
)
const
{
return
ptr_
[
i
];
}
void
remove_prefix
(
int
n
)
{
ptr_
+=
n
;
length_
-=
n
;
}
void
remove_suffix
(
int
n
)
{
length_
-=
n
;
}
bool
operator
==
(
const
StringPiece
&
x
)
const
{
return
((
length_
==
x
.
length_
)
&&
(
memcmp
(
ptr_
,
x
.
ptr_
,
length_
)
==
0
));
}
bool
operator
!=
(
const
StringPiece
&
x
)
const
{
return
!
(
*
this
==
x
);
}
void
remove_prefix
(
int
n
)
{
ptr_
+=
n
;
length_
-=
n
;
}
void
remove_suffix
(
int
n
)
{
length_
-=
n
;
}
bool
operator
==
(
const
StringPiece
&
x
)
const
{
return
((
length_
==
x
.
length_
)
&&
(
memcmp
(
ptr_
,
x
.
ptr_
,
length_
)
==
0
));
}
bool
operator
!=
(
const
StringPiece
&
x
)
const
{
return
!
(
*
this
==
x
);
}
#define STRINGPIECE_BINARY_PREDICATE(cmp, auxcmp) \
bool operator cmp(const StringPiece &x) const \
...
...
@@ -173,13 +130,8 @@ public:
return
r
;
}
std
::
string
as_string
()
const
{
return
std
::
string
(
data
(),
size
());
}
void
CopyToString
(
std
::
string
*
target
)
const
{
target
->
assign
(
ptr_
,
length_
);
}
std
::
string
as_string
()
const
{
return
std
::
string
(
data
(),
size
());
}
void
CopyToString
(
std
::
string
*
target
)
const
{
target
->
assign
(
ptr_
,
length_
);
}
// Does "this" start with "x"
bool
starts_with
(
const
StringPiece
&
x
)
const
{
...
...
jlib/base/thread.h
0 → 100644
View file @
bfc76fba
#
pragma
once
jlib/base/time.h
View file @
bfc76fba
#pragma once
#
pragma
once
// for cross-platform
...
...
jlib/base/timezone.h
View file @
bfc76fba
#pragma once
#
pragma
once
#include "config.h"
//
...
...
jlib/util/micro_getter_setter.h
View file @
bfc76fba
#pragma once
#
pragma
once
// getter & setter
...
...
@@ -44,7 +44,7 @@
} \
}
#define DECLARE_GETTER_SETTER_STRING(val) \
#define DECLARE_GETTER_SETTER_
C
STRING(val) \
DECLARE_GETTER(CString, val); \
DECLARE_SETTER(CString, val);
...
...
jlib/util/space.h
View file @
bfc76fba
...
...
@@ -2,12 +2,10 @@
#include <string>
#include <cmath>
#include <iomanip>
#include <sstream>
namespace
jlib
{
enum
PositionalNotation
{
enum
class
PositionalNotation
{
//! Used for memory size or Microsoft disk space
Binary
,
//! Usually used by Disk Space
...
...
@@ -17,18 +15,15 @@ enum PositionalNotation {
/**
* @brief Format byte count to human readable string
* @note bytes must less than 1DB(DoggaByte)
* @note http://programming.guide/java/formatting-byte-size-to-human-readable-format.html
*/
static
std
::
string
human_readable_byte_count
(
uintmax_t
bytes
,
size_t
precision
=
1
,
PositionalNotation
po
=
PositionalNotation
::
Binary
)
static
inline
std
::
string
human_readable_byte_count
(
uintmax_t
bytes
,
PositionalNotation
po
=
PositionalNotation
::
Binary
)
{
// http://programming.guide/java/formatting-byte-size-to-human-readable-format.html
auto
unit
=
po
==
PositionalNotation
::
Binary
?
1024
:
1000
;
if
(
bytes
<
unit
)
{
return
std
::
to_string
(
bytes
)
+
"B"
;
}
auto
exp
=
static_cast
<
size_t
>
(
std
::
log
(
bytes
)
/
std
::
log
(
unit
));
auto
pre
=
std
::
string
(
"KMGTPEZYBND"
).
at
(
exp
-
1
)
+
std
::
string
(
po
==
PositionalNotation
::
Binary
?
"i"
:
""
);
auto
var
=
bytes
/
std
::
pow
(
unit
,
exp
);
//std::stringstream ss;
//ss << std::fixed << std::setprecision(1) << var << pre << "B";
char
buf
[
64
]
=
{
0
};
snprintf
(
buf
,
sizeof
(
buf
),
"%.1lf%sB"
,
var
,
pre
.
data
());
return
buf
;
...
...
jlib/util/version.h
View file @
bfc76fba
#pragma once
#
pragma
once
#include "../base/config.h"
#include <string>
...
...
test/test.sln
View file @
bfc76fba
...
...
@@ -33,6 +33,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "base", "base", "{608A105E-4
..\jlib\base\noncopyable.h = ..\jlib\base\noncopyable.h
..\jlib\base\singleton.h = ..\jlib\base\singleton.h
..\jlib\base\stringpiece.h = ..\jlib\base\stringpiece.h
..\jlib\base\thread.h = ..\jlib\base\thread.h
..\jlib\base\time.h = ..\jlib\base\time.h
..\jlib\base\timestamp.h = ..\jlib\base\timestamp.h
..\jlib\base\timezone.h = ..\jlib\base\timezone.h
...
...
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