Skip to content

Commit d87baba

Browse files
authored
Merge pull request #61 from NickvisionApps/proc
V2025.3.3
2 parents 2109ed8 + 82c7fe6 commit d87baba

File tree

9 files changed

+278
-69
lines changed

9 files changed

+278
-69
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 2025.3.3
4+
### Breaking Changes
5+
None
6+
### New APIs
7+
#### Helpers
8+
- Added `includeEmpty` parameter to `StringHelpers::split()` function
9+
#### System
10+
- Added `Process::getRAMUsage()` function
11+
- Added `Process::getCPUUsage()` function
12+
### Fixes
13+
#### Helpers
14+
- Improved `StringHelpers::split()` implementation
15+
316
## 2025.3.2
417
### Breaking Changes
518
None

CMakeLists.txt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
2121

2222
#libnick Definition
23-
project ("libnick" LANGUAGES C CXX VERSION 2025.3.2 DESCRIPTION "A cross-platform base for native Nickvision applications.")
23+
project ("libnick" LANGUAGES C CXX VERSION 2025.3.3 DESCRIPTION "A cross-platform base for native Nickvision applications.")
2424
include(CMakePackageConfigHelpers)
2525
include(GNUInstallDirs)
2626
include(CTest)
@@ -148,29 +148,29 @@ export(EXPORT "${PROJECT_NAME}Targets" FILE "${CMAKE_BINARY_DIR}/cmake/${PROJECT
148148

149149
#libnick Test
150150
if (BUILD_TESTING)
151-
add_executable(${PROJECT_NAME}_test
152-
"tests/codetests.cpp"
153-
"tests/databasetests.cpp"
154-
"tests/datafiletests.cpp"
155-
"tests/dnstests.cpp"
156-
"tests/eventtests.cpp"
157-
"tests/filewatchertests.cpp"
158-
"tests/hardwaretests.cpp"
159-
"tests/ipctests.cpp"
160-
"tests/keyringtests.cpp"
161-
"tests/loggingtests.cpp"
162-
"tests/main.cpp"
163-
"tests/networktests.cpp"
164-
"tests/notificationtests.cpp"
165-
"tests/passwordtests.cpp"
166-
"tests/processtests.cpp"
167-
"tests/stringtests.cpp"
168-
"tests/systemcredentialstests.cpp"
169-
"tests/systemtests.cpp"
170-
"tests/taskbartests.cpp"
171-
"tests/updatertests.cpp"
172-
"tests/versiontests.cpp"
173-
"tests/webtests.cpp")
174-
find_package(GTest CONFIG REQUIRED)
175-
target_link_libraries(${PROJECT_NAME}_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main ${PROJECT_NAME})
151+
add_executable(${PROJECT_NAME}_test
152+
"tests/codetests.cpp"
153+
"tests/databasetests.cpp"
154+
"tests/datafiletests.cpp"
155+
"tests/dnstests.cpp"
156+
"tests/eventtests.cpp"
157+
"tests/filewatchertests.cpp"
158+
"tests/hardwaretests.cpp"
159+
"tests/ipctests.cpp"
160+
"tests/keyringtests.cpp"
161+
"tests/loggingtests.cpp"
162+
"tests/main.cpp"
163+
"tests/networktests.cpp"
164+
"tests/notificationtests.cpp"
165+
"tests/passwordtests.cpp"
166+
"tests/processtests.cpp"
167+
"tests/stringtests.cpp"
168+
"tests/systemcredentialstests.cpp"
169+
"tests/systemtests.cpp"
170+
"tests/taskbartests.cpp"
171+
"tests/updatertests.cpp"
172+
"tests/versiontests.cpp"
173+
"tests/webtests.cpp")
174+
find_package(GTest CONFIG REQUIRED)
175+
target_link_libraries(${PROJECT_NAME}_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main ${PROJECT_NAME})
176176
endif()

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "libnick"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = "2025.3.2"
51+
PROJECT_NUMBER = "2025.3.3"
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

include/helpers/stringhelpers.h

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,39 +100,6 @@ namespace Nickvision::Helpers::StringHelpers
100100
* @return The new replaced string
101101
*/
102102
std::string replace(std::string s, char toReplace, char replace);
103-
/**
104-
* @brief Splits a string based on a delimiter.
105-
* @tparam T The type of the resulting splits (must be a type that can be implicitly converted to string)
106-
* @param s The string to split
107-
* @param delimiter The delimiter to split the string on
108-
* @return The splits of the string
109-
*/
110-
template<StringImplicitlyConstructible T = std::string>
111-
std::vector<T> split(std::string s, const std::string& delimiter)
112-
{
113-
if(s.empty())
114-
{
115-
return { "" };
116-
}
117-
std::vector<T> splits;
118-
if(delimiter.empty())
119-
{
120-
splits.push_back(s);
121-
return splits;
122-
}
123-
size_t pos{ 0 };
124-
while ((pos = s.find(delimiter)) != std::string::npos)
125-
{
126-
std::string split{ s.substr(0, pos) };
127-
splits.push_back(split);
128-
s.erase(0, pos + 1);
129-
}
130-
if (!s.empty())
131-
{
132-
splits.push_back(s);
133-
}
134-
return splits;
135-
}
136103
/**
137104
* @brief Splits a string based on argument delimiters.
138105
* @param s The string to split
@@ -180,6 +147,50 @@ namespace Nickvision::Helpers::StringHelpers
180147
* @return The wstring version of the string
181148
*/
182149
std::wstring wstr(const std::string& s);
150+
/**
151+
* @brief Splits a string based on a delimiter.
152+
* @tparam T The type of the resulting splits (must be a type that can be implicitly converted to string)
153+
* @param s The string to split
154+
* @param delimiter The delimiter to split the string on
155+
* @param includeEmpty Whether or not to include empty tokens
156+
* @return The splits of the string
157+
*/
158+
template<StringImplicitlyConstructible T = std::string>
159+
std::vector<T> split(const std::string& s, const std::string& delimiter, bool includeEmpty = true)
160+
{
161+
std::vector<T> splits;
162+
size_t last{ 0 };
163+
size_t next{ 0 };
164+
while((next = s.find(delimiter, last)) != std::string::npos)
165+
{
166+
std::string token{ s.substr(last, next - last) };
167+
if(includeEmpty || !trim(token).empty())
168+
{
169+
splits.push_back(token);
170+
}
171+
last = next + delimiter.length();
172+
173+
}
174+
std::string finalToken{ s.substr(last) };
175+
if(includeEmpty || !trim(finalToken).empty())
176+
{
177+
splits.push_back(finalToken);
178+
}
179+
return splits;
180+
}
181+
/**
182+
* @brief Splits a string based on a delimiter.
183+
* @tparam T The type of the resulting splits (must be a type that can be implicitly converted to string)
184+
* @param s The string to split
185+
* @param delimiter The delimiter to split the string on
186+
* @param includeEmpty Whether or not to include empty tokens
187+
* @return The splits of the string
188+
*/
189+
template<StringImplicitlyConstructible T = std::string>
190+
std::vector<T> split(const std::string& s, char delimiter, bool includeEmpty = true)
191+
{
192+
return split<T>(s, std::string(1, delimiter), includeEmpty);
193+
}
183194
}
184195

185196
#endif // STRINGHELPERS_H

include/system/process.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ namespace Nickvision::System
8989
* @return The console output of the process. Empty if the process has not completed
9090
*/
9191
const std::string& getOutput() const;
92+
/**
93+
* @brief Gets the amount of RAM being used by the process in bytes.
94+
* @return The amount of RAM used by the process
95+
*/
96+
unsigned long long getRAMUsage() const;
97+
/**
98+
* @brief Gets the percent of the CPU being used by the process.
99+
* @return The CPU usage of the process
100+
*/
101+
double getCPUUsage() const;
92102
/**
93103
* @brief Starts the process.
94104
* @return True if the process was started, else false
@@ -141,10 +151,15 @@ namespace Nickvision::System
141151
HANDLE m_childInWrite;
142152
PROCESS_INFORMATION m_pi;
143153
HANDLE m_job;
154+
mutable ULARGE_INTEGER m_lastKernelTime;
155+
mutable ULARGE_INTEGER m_lastUserTime;
156+
mutable ULARGE_INTEGER m_lastSystemTime;
144157
#else
145158
int m_childOutPipes[2];
146159
int m_childInPipes[2];
147160
pid_t m_pid;
161+
mutable unsigned long long m_lastUserTime;
162+
mutable unsigned long long m_lastSystemTime;
148163
#endif
149164
};
150165
}

manual/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66

77
libnick provides Nickvision apps with a common set of cross-platform APIs for managing system and desktop app functionality such as network management, taskbar icons, translations, app updates, and more.
88

9-
## 2025.3.2
9+
## 2025.3.3
1010
### Breaking Changes
1111
None
1212
### New APIs
13+
#### Helpers
14+
- Added `includeEmpty` parameter to `StringHelpers::split()` function
1315
#### System
14-
- Added `Process::send()` function
15-
- Added `Process::sendCommand()` function
16+
- Added `Process::getRAMUsage()` function
17+
- Added `Process::getCPUUsage()` function
1618
### Fixes
17-
None
19+
#### Helpers
20+
- Improved `StringHelpers::split()` implementation
1821

1922
## Dependencies
2023
The following are a list of dependencies used by libnick.

0 commit comments

Comments
 (0)