Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rlib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
rlib
Commits
a2513f74
There was an error fetching the commit references. Please try again later.
Commit
a2513f74
authored
5 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
add fs prettyprint (not enabled), adjust prettyprint interface
parent
c3d3648e
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
3rdparty/fs_prettyprint.hpp
+96
-0
96 additions, 0 deletions
3rdparty/fs_prettyprint.hpp
3rdparty/prettyprint.hpp
+5
-6
5 additions, 6 deletions
3rdparty/prettyprint.hpp
3rdparty/test.cc
+3
-3
3 additions, 3 deletions
3rdparty/test.cc
sys/unix_handy.hpp
+17
-0
17 additions, 0 deletions
sys/unix_handy.hpp
with
121 additions
and
9 deletions
3rdparty/fs_prettyprint.hpp
0 → 100644
+
96
−
0
View file @
a2513f74
#ifndef RLIB_FS_STATUS_PRETTYPRINT
#define RLIB_FS_STATUS_PRETTYPRINT
#include
<filesystem>
#include
<iomanip>
#include
<ostream>
#include
<string>
#include
<rlib/require/cxx17>
namespace
rlib
::
prettyprint
{
namespace
impl
{
inline
std
::
string
ftypeToString
(
const
std
::
filesystem
::
file_type
&
t
)
{
switch
(
t
)
{
case
std
::
filesystem
::
file_type
::
regular
:
return
"regular file"
;
case
std
::
filesystem
::
file_type
::
directory
:
return
"directory"
;
case
std
::
filesystem
::
file_type
::
symlink
:
return
"symlink"
;
case
std
::
filesystem
::
file_type
::
block
:
return
"block file"
;
case
std
::
filesystem
::
file_type
::
character
:
return
"character file"
;
case
std
::
filesystem
::
file_type
::
fifo
:
return
"fifo"
;
case
std
::
filesystem
::
file_type
::
socket
:
return
"socket"
;
case
std
::
filesystem
::
file_type
::
unknown
:
return
"unknown"
;
case
std
::
filesystem
::
file_type
::
none
:
return
"none"
;
case
std
::
filesystem
::
file_type
::
not_found
:
return
"not_found"
;
}
return
""
;
}
inline
std
::
string
fsizeToString
(
const
size_t
fsize
)
{
if
(
fsize
<
1024
)
return
std
::
to_string
(
fsize
);
const
auto
KiB
=
(
double
)
fsize
/
1024.
;
if
(
KiB
<
1024
)
return
std
::
to_string
(
KiB
)
+
"Ki"
;
const
auto
MiB
=
KiB
/
1024.
;
if
(
MiB
<
1024
)
return
std
::
to_string
(
MiB
)
+
"Mi"
;
const
auto
GiB
=
MiB
/
1024.
;
if
(
GiB
<
1024
)
return
std
::
to_string
(
GiB
)
+
"Gi"
;
const
auto
TiB
=
GiB
/
1024.
;
if
(
TiB
<
1024
)
return
std
::
to_string
(
TiB
)
+
"Ti"
;
const
auto
PiB
=
TiB
/
1024.
;
return
std
::
to_string
(
PiB
)
+
"Pi"
;
}
template
<
typename
T
>
std
::
string
try_show_file_size
(
const
T
&
arg
)
{
try
{
return
fsizeToString
(
std
::
filesystem
::
file_size
(
arg
));
}
catch
(...)
{
return
"-"
;
}
}
}
template
<
typename
CharT
,
typename
Traits
>
std
::
basic_ostream
<
CharT
,
Traits
>&
operator
<<
(
std
::
basic_ostream
<
CharT
,
Traits
>
&
os
,
const
std
::
filesystem
::
perms
&
p
)
{
return
os
<<
((
p
&
std
::
filesystem
::
perms
::
owner_read
)
!=
std
::
filesystem
::
perms
::
none
?
"r"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
owner_write
)
!=
std
::
filesystem
::
perms
::
none
?
"w"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
owner_exec
)
!=
std
::
filesystem
::
perms
::
none
?
"x"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
group_read
)
!=
std
::
filesystem
::
perms
::
none
?
"r"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
group_write
)
!=
std
::
filesystem
::
perms
::
none
?
"w"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
group_exec
)
!=
std
::
filesystem
::
perms
::
none
?
"x"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
others_read
)
!=
std
::
filesystem
::
perms
::
none
?
"r"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
others_write
)
!=
std
::
filesystem
::
perms
::
none
?
"w"
:
"-"
)
<<
((
p
&
std
::
filesystem
::
perms
::
others_exec
)
!=
std
::
filesystem
::
perms
::
none
?
"x"
:
"-"
)
;
}
template
<
typename
CharT
,
typename
Traits
>
std
::
basic_ostream
<
CharT
,
Traits
>&
operator
<<
(
std
::
basic_ostream
<
CharT
,
Traits
>
&
os
,
const
std
::
filesystem
::
file_type
&
t
)
{
return
os
<<
impl
::
ftypeToString
(
t
);
}
template
<
typename
CharT
,
typename
Traits
>
std
::
basic_ostream
<
CharT
,
Traits
>&
operator
<<
(
std
::
basic_ostream
<
CharT
,
Traits
>
&
os
,
const
std
::
filesystem
::
directory_entry
&
entry
)
{
#if RLIB_CXX_STD >= 2020
auto
lastWriteInSysClock
=
std
::
chrono
::
clock_cast
<
std
::
chrono
::
system_clock
>
(
entry
.
last_write_time
());
#else
#error A BUG NOT RESOLVED NOW. DO NOT USE THIS LIB.
auto
lastWriteInSysClock
=
entry
.
last_write_time
();
#endif
auto
lastWrite
=
std
::
chrono
::
system_clock
::
to_time_t
(
lastWriteInSysClock
);
return
os
<<
entry
.
status
().
permissions
()
<<
' '
<<
impl
::
try_show_file_size
(
entry
)
<<
' '
<<
std
::
put_time
(
std
::
localtime
(
&
lastWrite
),
"%F %T"
)
<<
' '
<<
entry
.
status
().
type
();
}
}
// end namespace rlib::prettyprint
#endif
This diff is collapsed.
Click to expand it.
3rdparty/prettyprint.hpp
+
5
−
6
View file @
a2513f74
...
@@ -30,10 +30,9 @@
...
@@ -30,10 +30,9 @@
#include
<utility>
#include
<utility>
#include
<valarray>
#include
<valarray>
#ifndef RLIB_3RD_ENABLE_PRETTYPRINT
namespace
rlib
{
namespace
rlib
{
namespace
_3rdparty
{
namespace
_3rdparty
{
#endif
// 3rd party code begin
namespace
pretty_print
namespace
pretty_print
{
{
namespace
detail
namespace
detail
...
@@ -451,11 +450,11 @@ namespace std
...
@@ -451,11 +450,11 @@ namespace std
return
stream
<<
pretty_print
::
print_container_helper
<
T
,
TChar
,
TCharTraits
>
(
container
);
return
stream
<<
pretty_print
::
print_container_helper
<
T
,
TChar
,
TCharTraits
>
(
container
);
}
}
}
}
#ifndef RLIB_3RD_ENABLE_PRETTYPRINT
// 3rd party code end.
}
}
}
// end namespace rlib::3rdparty
}
// end namespace rlib::3rdparty
#endif // RLIB_3RD_ENABLE_PRETTYPRINT
namespace
rlib
{
namespace
prettyprint
=
::
rlib
::
_3rdparty
::
std
;
}
#endif // H_PRETTY_PRINT
#endif // H_PRETTY_PRINT
This diff is collapsed.
Click to expand it.
3rdparty/test.cc
+
3
−
3
View file @
a2513f74
#include
"prettyprint.hpp"
#include
"prettyprint.hpp"
#include
<rlib/stdio.hpp>
#include
<rlib/stdio.hpp>
#include
<list>
#include
<list>
using
namespace
rlib
;
using
namespace
rlib
::
prettyprint
;
int
main
()
{
int
main
()
{
std
::
list
ls
{
1
,
3
,
2
};
std
::
list
<
int
>
ls
{
1
,
3
,
2
};
_3rdparty
::
std
::
operator
<<
(
std
::
cout
,
ls
)
;
std
::
cout
<<
ls
;
}
}
This diff is collapsed.
Click to expand it.
sys/unix_handy.hpp
+
17
−
0
View file @
a2513f74
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#define RLIB_UNIX_HANDY_HPP_
#define RLIB_UNIX_HANDY_HPP_
#include
<unistd.h>
#include
<unistd.h>
#include
<sys/socket.h>
#include
<sys/socket.h>
#include
<sys/types.h>
#include
<sys/types.h>
#include
<netdb.h>
#include
<netdb.h>
...
@@ -13,6 +14,22 @@
...
@@ -13,6 +14,22 @@
#error rlib/sys/unix_handy.hpp is not for Windows.
#error rlib/sys/unix_handy.hpp is not for Windows.
#endif
#endif
namespace
rlib
{
// args DOES NOT contain the "$0".
inline
void
execs
(
std
::
string
path
,
std
::
vector
<
std
::
string
>
args
)
{
const
size_t
max_args
=
1022
;
if
(
args
.
size
()
>
max_args
)
throw
std
::
out_of_range
(
"too many arguments"
);
char
*
arr
[
max_args
+
2
];
arr
[
0
]
=
(
char
*
)
path
.
c_str
();
for
(
auto
cter
=
0
;
cter
<
args
.
size
();
++
cter
)
arr
[
cter
+
1
]
=
(
char
*
)
args
[
cter
].
c_str
();
arr
[
args
.
size
()
+
1
]
=
0
;
::
execv
(
path
.
c_str
(),
arr
);
}
}
// Deprecated. Use sys/sio.hpp
// Deprecated. Use sys/sio.hpp
#if 1+1 == 4
#if 1+1 == 4
namespace
rlib
{
namespace
rlib
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment