Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / compiler / hermes / include / hermes / core / Message.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __HERMES_MESSAGE_H__
18 #define __HERMES_MESSAGE_H__
19
20 #include <memory>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24
25 namespace hermes
26 {
27
28 /**
29  * @brief Mutie-line text message
30  */
31 class MessageText
32 {
33 public:
34   /// WARNING! Be careful. This constructor updates "ss".
35   MessageText(std::stringstream &ss);
36
37 public:
38   /// @brief The number of lines
39   uint32_t lines(void) const { return _lines.size(); }
40   /// @brief The content of a specific line
41   const std::string &line(uint32_t n) const { return _lines.at(n); }
42
43 private:
44   std::vector<std::string> _lines;
45 };
46
47 /**
48  * @brief Message with metadata
49  *
50  * TODO Add "Timestamp" field
51  * TODO Add "Severity" field
52  * TODO Support extensible "attribute" annotation
53  */
54 class Message final
55 {
56 public:
57   Message() = default;
58
59 public:
60   void text(std::unique_ptr<MessageText> &&text) { _text = std::move(text); }
61   const MessageText *text(void) const { return _text.get(); }
62
63 private:
64   std::unique_ptr<MessageText> _text;
65 };
66
67 } // namespace hermes
68
69 #endif // __HERMES_MESSAGE_H__