#include <functional>
#include <map>
#include <memory>
#include <string>
#include <vector>
浏览源代码.
|
template<typename T > |
T | toValue (const uint8_t *add, int &index) |
|
template<typename T > |
T | toValue (const char *add, int &index) |
|
bool | createFileAndWrite (const std::string &filename, const std::string &content) |
|
bool | AppendCsv (const std::string &filename, const std::vector< std::string > &data) |
|
◆ AppendCsv()
bool AppendCsv |
( |
const std::string & |
filename, |
|
|
const std::vector< std::string > & |
data |
|
) |
| |
在文件 protocol_asensing.cc 第 194 行定义.
195 {
196 std::ofstream file(filename, std::ios_base::app);
197 if (!file.is_open()) {
198 std::cerr << "无法打开文件 " << filename << "\n";
199 return false;
200 }
201
202 std::ostringstream oss;
203 for (const auto& s : data) {
204 oss << s << ",";
205 }
206 std::string line = oss.str();
207 if (!line.empty()) {
208 line.pop_back();
209 }
210 line += "\n";
211
212 file << line;
213
214 file.close();
215 return true;
216}
◆ createFileAndWrite()
bool createFileAndWrite |
( |
const std::string & |
filename, |
|
|
const std::string & |
content |
|
) |
| |
在文件 protocol_asensing.cc 第 172 行定义.
173 {
174 std::ifstream checkFile(filename);
175 if (checkFile.good()) {
176 std::cout << "文件已存在: " << filename << std::endl;
177 return false;
178 }
179 checkFile.close();
180
181 std::ofstream file(filename);
182 if (!file) {
183 std::cerr << "无法创建文件: " << filename << std::endl;
184 return false;
185 }
186
187 file << content << std::endl;
188 file.close();
189
190 std::cout << "已写入文件: " << filename << std::endl;
191 return true;
192}
◆ toValue() [1/2]
template<typename T >
T toValue |
( |
const char * |
add, |
|
|
int & |
index |
|
) |
| |
在文件 protocol_asensing.h 第 76 行定义.
76 {
77 T result = *reinterpret_cast<const T*>(add + index);
78 index += sizeof(T);
79 return result;
80}
◆ toValue() [2/2]
template<typename T >
T toValue |
( |
const uint8_t * |
add, |
|
|
int & |
index |
|
) |
| |
在文件 protocol_asensing.h 第 69 行定义.
69 {
70 T result = *reinterpret_cast<const T*>(add + index);
71 index += sizeof(T);
72 return result;
73}