Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
UERANSIM
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
UERANSIM
Commits
aba93a5d
Commit
aba93a5d
authored
Feb 11, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IO utils improvement
parent
155cddc1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
5 deletions
+42
-5
CMakeLists.txt
CMakeLists.txt
+2
-1
src/utils/common.cpp
src/utils/common.cpp
+6
-0
src/utils/common.hpp
src/utils/common.hpp
+1
-0
src/utils/constants.hpp
src/utils/constants.hpp
+2
-1
src/utils/io.cpp
src/utils/io.cpp
+24
-2
src/utils/io.hpp
src/utils/io.hpp
+7
-1
No files found.
CMakeLists.txt
View file @
aba93a5d
...
...
@@ -72,4 +72,5 @@ add_executable(nr-cli src/cli.cpp)
target_link_libraries
(
nr-cli pthread
)
target_compile_options
(
nr-cli PRIVATE -Wall -Wextra -pedantic
)
target_link_libraries
(
nr-cli utils
)
\ No newline at end of file
target_link_libraries
(
nr-cli app
)
target_link_libraries
(
nr-cli utils
)
src/utils/common.cpp
View file @
aba93a5d
...
...
@@ -7,6 +7,7 @@
//
#include "common.hpp"
#include <algorithm>
#include <atomic>
#include <chrono>
#include <random>
...
...
@@ -295,3 +296,8 @@ void utils::AssertNodeName(const std::string &str)
"' contains illegal character: "
+
std
::
string
(
1
,
c
));
}
}
bool
utils
::
IsNumeric
(
const
std
::
string
&
str
)
{
return
!
str
.
empty
()
&&
std
::
all_of
(
str
.
begin
(),
str
.
end
(),
[](
char
c
)
{
return
(
c
>=
'0'
&&
c
<=
'9'
);
});
}
src/utils/common.hpp
View file @
aba93a5d
...
...
@@ -32,6 +32,7 @@ int ParseInt(const char *str);
uint64_t
Random64
();
void
Sleep
(
int
ms
);
bool
IsRoot
();
bool
IsNumeric
(
const
std
::
string
&
str
);
void
AssertNodeName
(
const
std
::
string
&
str
);
template
<
typename
T
>
...
...
src/utils/constants.hpp
View file @
aba93a5d
...
...
@@ -28,5 +28,6 @@ struct cons
// Others
static
constexpr
const
char
*
CMD_SERVER_IP
=
"127.0.0.1"
;
static
constexpr
const
char
*
PROC_TABLE_DIR
=
"/tmp/UERANSIM.proc-table/"
;
static
constexpr
const
char
*
PROC_TABLE_DIR
=
"/tmp/UERANSIM.proc-table/"
;
static
constexpr
const
char
*
PROCESS_DIR
=
"/proc/"
;
};
src/utils/io.cpp
View file @
aba93a5d
...
...
@@ -26,13 +26,13 @@ std::string ReadAllText(const std::string &file)
void
CreateDirectory
(
const
std
::
string
&
path
)
{
if
(
!
std
::
filesystem
::
e
xists
(
path
))
if
(
!
E
xists
(
path
))
{
if
(
!
std
::
filesystem
::
is_directory
(
path
))
throw
std
::
runtime_error
(
"Required path '"
+
path
+
"' exists but not a directory."
);
std
::
filesystem
::
create_directory
(
path
);
std
::
filesystem
::
permissions
(
path
,
std
::
filesystem
::
perms
::
all
);
RelaxPermissions
(
path
);
}
}
...
...
@@ -41,4 +41,26 @@ bool Exists(const std::string &path)
return
std
::
filesystem
::
exists
(
path
);
}
void
WriteAllText
(
const
std
::
string
&
path
,
const
std
::
string
&
content
)
{
std
::
ofstream
ofs
{};
ofs
.
exceptions
(
std
::
ofstream
::
failbit
|
std
::
ofstream
::
badbit
);
ofs
.
open
(
path
);
ofs
<<
content
;
ofs
.
close
();
RelaxPermissions
(
path
);
}
void
RelaxPermissions
(
const
std
::
string
&
path
)
{
std
::
filesystem
::
permissions
(
path
,
std
::
filesystem
::
perms
::
all
);
}
bool
Remove
(
const
std
::
string
&
path
)
{
std
::
error_code
err
{};
std
::
filesystem
::
remove_all
(
path
,
err
);
return
(
bool
)
err
;
}
}
// namespace io
src/utils/io.hpp
View file @
aba93a5d
...
...
@@ -13,8 +13,14 @@ namespace io
void
CreateDirectory
(
const
std
::
string
&
path
);
bool
Exists
(
const
std
::
string
&
path
);
std
::
string
ReadAllText
(
const
std
::
string
&
file
);
bool
Exists
(
const
std
::
string
&
path
);
void
WriteAllText
(
const
std
::
string
&
path
,
const
std
::
string
&
content
);
void
RelaxPermissions
(
const
std
::
string
&
path
);
bool
Remove
(
const
std
::
string
&
path
);
}
// namespace io
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