2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
26 #include <boost/algorithm/string/join.hpp>
30 std::list<std::string>& context_stacks_per_thread()
32 static thread_local std::list<std::string> instances;
41 std::list<std::string>& context_stack_for_thread()
43 return context_stacks_per_thread();
46 std::string get_context()
48 return boost::join(context_stack_for_thread(), "");
51 scoped_context::scoped_context()
52 : scoped_context::scoped_context("")
56 scoped_context::scoped_context(std::string msg)
57 : for_thread_(context_stack_for_thread())
59 for_thread_.push_back(std::move(msg));
60 msg_ = &for_thread_.back();
63 void scoped_context::replace_msg(std::string msg)
65 if (&for_thread_ != &context_stack_for_thread())
66 CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Called from wrong thread"));
68 *msg_ = std::move(msg);
71 void scoped_context::clear_msg()
76 scoped_context::~scoped_context()
78 for_thread_.pop_back();
83 std::string get_message_and_context(const caspar_exception& e)
87 auto msg = boost::get_error_info<msg_info_t>(e);
88 auto ctx = boost::get_error_info<context_info_t>(e);
93 if (ctx && !ctx->empty())
100 if (!result.empty() && result.back() != '.')