OSDN Git Service

2010-08-12 Kostya Serebryany <kcc@google.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / src / future.cc
1 // future -*- C++ -*-
2
3 // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library 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.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 #include <future>
26
27 namespace
28 {
29   struct future_error_category : public std::error_category
30   {
31     future_error_category() {}
32
33     virtual const char*
34     name() const 
35     { return "future"; }
36
37     virtual std::string message(int __ec) const
38     {
39       std::string __msg;
40       switch (std::future_errc(__ec))
41       {
42       case std::future_errc::broken_promise:
43           __msg = "Broken promise";
44           break;
45       case std::future_errc::future_already_retrieved:
46           __msg = "Future already retrieved";
47           break;
48       case std::future_errc::promise_already_satisfied:
49           __msg = "Promise already satisfied";
50           break;
51       default:
52           __msg = "Unknown error";
53           break;
54       }
55       return __msg;
56     }
57   };
58
59   const future_error_category&
60   __future_category_instance()
61   {
62     static const future_error_category __fec;
63     return __fec;
64   }
65 }
66
67 namespace std
68 {
69   const error_category* const future_category = &__future_category_instance();
70
71   future_error::~future_error() throw() { }
72
73   const char* 
74   future_error::what() const throw() { return _M_code.message().c_str(); }
75 }