未验证 提交 13f89d70 编写于 作者: J Jeff Wang 提交者: GitHub

Add string checks before setting Mode and Tag (#214)

Fix some typos
上级 5d68c662
......@@ -95,14 +95,14 @@ for step in range(100):
#include "visualdl/sdk.h"
namespace vs = visualdl;
namepsace cp = visualdl::components;
namespace cp = visualdl::components;
int main() {
const std::string dir = "./tmp";
vs::LogWriter logger(dir, 10);
logger.SetMode("train");
auto tablet = logger.NewTablet("scalars/scalar0");
auto tablet = logger.AddTablet("scalars/scalar0");
cp::Scalar<float> scalar0(tablet);
......
......@@ -81,14 +81,14 @@ The same code for C++ SDK in the above Python SDK is as follows
#include "visualdl/sdk.h"
namespace vs = visualdl;
namepsace cp = visualdl::components;
namespace cp = visualdl::components;
int main() {
const std::string dir = "./tmp";
vs::LogWriter logger(dir, 10);
logger.SetMode("train");
auto tablet = logger.NewTablet("scalars/scalar0");
auto tablet = logger.AddTablet("scalars/scalar0");
cp::Scalar<float> scalar0(tablet);
......
......@@ -30,6 +30,11 @@ namespace visualdl {
std::string g_log_dir;
LogWriter LogWriter::AsMode(const std::string& mode) {
for (auto ch : "%/") {
CHECK(mode.find(ch) == std::string::npos)
<< "character "<< ch << " is a reserved word, it is not allowed in mode.";
}
LogWriter writer = *this;
storage_.AddMode(mode);
writer.mode_ = mode;
......@@ -37,7 +42,9 @@ LogWriter LogWriter::AsMode(const std::string& mode) {
}
Tablet LogWriter::AddTablet(const std::string& tag) {
// TODO(ChunweiYan) add string check here.
CHECK(tag.find("%") == std::string::npos)
<< "character % is a reserved word, it is not allowed in tag.";
auto tmp = mode_ + "/" + tag;
string::TagEncode(tmp);
auto res = storage_.AddTablet(tmp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册