OR-Tools  9.3
message_callback.h
Go to the documentation of this file.
1// Copyright 2010-2021 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_CPP_MESSAGE_CALLBACK_H_
15#define OR_TOOLS_MATH_OPT_CPP_MESSAGE_CALLBACK_H_
16
17#include <functional>
18#include <iostream>
19#include <string>
20
21#include "absl/strings/string_view.h"
23
25
26// Callback function for messages callback sent by the solver.
27//
28// Each message represents a single output line from the solver, and each
29// message does not contain any '\n' character in it.
30//
31// Thread-safety: a callback may be called concurrently from multiple
32// threads. The users is expected to use proper synchronization primitives to
33// deal with that.
34using MessageCallback = std::function<void(const std::vector<std::string>&)>;
35
36// Returns a message callback function that prints its output to the given
37// output stream, prefixing each line with the given prefix.
38//
39// For each call to the returned message callback, the output_stream is flushed.
40//
41// Usage:
42//
43// SolveArguments args;
44// args.message_callback = PrinterMessageCallback(std::cerr, "solver logs> ");
45MessageCallback PrinterMessageCallback(std::ostream& output_stream = std::cout,
46 absl::string_view prefix = "");
47
48} // namespace operations_research::math_opt
49
50#endif // OR_TOOLS_MATH_OPT_CPP_MESSAGE_CALLBACK_H_
MessageCallback PrinterMessageCallback(std::ostream &output_stream, const absl::string_view prefix)
std::function< void(const std::vector< std::string > &)> MessageCallback