From 13f89d700ea3e73650d0f70f8035620507323538 Mon Sep 17 00:00:00 2001 From: Jeff Wang Date: Thu, 25 Jan 2018 16:30:25 -0800 Subject: [PATCH] Add string checks before setting Mode and Tag (#214) Fix some typos --- README.cn.md | 4 ++-- docs/README.md | 4 ++-- visualdl/logic/sdk.cc | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.cn.md b/README.cn.md index 5da482d5..9236024f 100644 --- a/README.cn.md +++ b/README.cn.md @@ -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 scalar0(tablet); diff --git a/docs/README.md b/docs/README.md index 40429233..8825363c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 scalar0(tablet); diff --git a/visualdl/logic/sdk.cc b/visualdl/logic/sdk.cc index 7436bc1f..864b4598 100644 --- a/visualdl/logic/sdk.cc +++ b/visualdl/logic/sdk.cc @@ -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); -- GitLab