Skip to content

Commit 996ef64

Browse files
author
Gin
committed
comment to JSON lib and add ML annotation path
1 parent b6cf566 commit 996ef64

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

Common/Cpp/Json/JsonTools.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void string_to_file(const std::string& filename, const std::string& str){
3838
}
3939
file.close();
4040
}
41+
42+
4143
std::string file_to_string(const std::string& filename){
4244
QFile file(QString::fromStdString(filename));
4345
if (!file.open(QFile::ReadOnly)){
@@ -47,6 +49,16 @@ std::string file_to_string(const std::string& filename){
4749
}
4850

4951

52+
bool file_to_string(const std::string& filename, std::string& content){
53+
QFile file(QString::fromStdString(filename));
54+
if (!file.open(QFile::ReadOnly)){
55+
return false;
56+
}
57+
content = file.readAll().toStdString();
58+
return true;
59+
}
60+
61+
5062

5163

5264
JsonValue from_nlohmann(const nlohmann::json& json){

Common/Cpp/Json/JsonTools.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ namespace PokemonAutomation{
1717

1818

1919
void string_to_file(const std::string& filename, const std::string& str);
20+
// Load file from `filename` into a string
21+
// If unable to open the file, FileException is thrown
2022
std::string file_to_string(const std::string& filename);
23+
// Load file from `filename` into a string. Return true if the file can be read successfully
24+
bool file_to_string(const std::string& filename, std::string& content);
2125

2226
JsonValue from_nlohmann(const nlohmann::json& json);
2327
nlohmann::json to_nlohmann(const JsonValue& json);

Common/Cpp/Json/JsonValue.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ class JsonValue{
160160
} u;
161161
};
162162

163+
// Given a string as a raw JSON, parse it into a `JsonValue`.
164+
// If there is error parsing the JSON, it will not throw exception.
165+
// The input string is usually loaded directly from a JSON file.
166+
// You can call JsonTools.h:file_to_string() to load a file as a raw JSON string.
163167
JsonValue parse_json(const std::string& str);
168+
// Load file from `filename` and parse it into a `JsonValue`.
169+
// If unable to open the file, FileException is thrown
170+
// If there is error parsing the JSON, it will not throw exception.
164171
JsonValue load_json_file(const std::string& filename);
165172

166173

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ const std::string& TRAINING_PATH(){
200200
return path;
201201
}
202202

203-
203+
const std::string& ML_ANNOTATION_PATH(){
204+
static const std::string path = RUNTIME_BASE_PATH() + "DataAnnotation/";
205+
return path;
206+
}
204207

205208
}
206209

SerialPrograms/Source/CommonFramework/Globals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ const std::string& RESOURCE_PATH();
6060
// Hold ML training data.
6161
const std::string& TRAINING_PATH();
6262

63+
// Folder path (end with "/") to hold data annotation for ML labeling programs
64+
const std::string& ML_ANNOTATION_PATH();
65+
6366

6467
enum class ProgramState{
6568
NOT_READY,

0 commit comments

Comments
 (0)