OR-Tools  9.6
message_callback_data.h
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_MATH_OPT_SOLVERS_MESSAGE_CALLBACK_DATA_H_
15 #define OR_TOOLS_MATH_OPT_SOLVERS_MESSAGE_CALLBACK_DATA_H_
16 
17 #include <optional>
18 #include <string>
19 #include <string_view>
20 #include <vector>
21 
22 namespace operations_research {
23 namespace math_opt {
24 
25 // Buffer for solvers messages that enforces the contract of MessageCallback.
26 //
27 // This contract mandates that each message is a full finished line. As a
28 // consequence, if the solver calls the callback with a partial last line, this
29 // one must not be passed immediately to MessageCallback but kept until the end
30 // of the line is reached (or the solve is done).
31 //
32 // To implement that this class has two methods:
33 //
34 // - Parse() that is to be called for each received message from the solver.
35 //
36 // - Flush() that must be called at the end of the solve to generate the data
37 // corresponding the last message sent by the solver if it was an unfinished -
38 // line.
40  public:
41  MessageCallbackData() = default;
42 
45 
46  // Parses the input message, returning a vector with all finished
47  // lines. Returns an empty vector if the input message did not contained any
48  // '\n'.
49  //
50  // It updates this object with the last unfinished line to use it to complete
51  // the next message.
52  std::vector<std::string> Parse(std::string_view message);
53 
54  // Returns a vector with the last unfinished line if it exists, else an empty
55  // vector.
56  std::vector<std::string> Flush();
57 
58  private:
59  // The last message line not ending with '\n'.
60  std::string unfinished_line_;
61 };
62 
63 } // namespace math_opt
64 } // namespace operations_research
65 
66 #endif // OR_TOOLS_MATH_OPT_SOLVERS_MESSAGE_CALLBACK_DATA_H_
MessageCallbackData(const MessageCallbackData &)=delete
std::vector< std::string > Parse(std::string_view message)
MessageCallbackData & operator=(const MessageCallbackData &)=delete
Collection of objects used to extend the Constraint Solver library.
std::string message
Definition: trace.cc:399