| 1 | // Copyright 2016 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "cctz/zone_info_source.h" |
| 16 | |
| 17 | namespace cctz { |
| 18 | |
| 19 | // Defined out-of-line to avoid emitting a weak vtable in all TUs. |
| 20 | ZoneInfoSource::~ZoneInfoSource() {} |
| 21 | |
| 22 | } // namespace cctz |
| 23 | |
| 24 | namespace cctz_extension { |
| 25 | |
| 26 | namespace { |
| 27 | |
| 28 | // A default for cctz_extension::zone_info_source_factory, which simply |
| 29 | // defers to the fallback factory. |
| 30 | std::unique_ptr<cctz::ZoneInfoSource> DefaultFactory( |
| 31 | const std::string& name, |
| 32 | const std::function<std::unique_ptr<cctz::ZoneInfoSource>( |
| 33 | const std::string& name)>& fallback_factory) { |
| 34 | return fallback_factory(name); |
| 35 | } |
| 36 | |
| 37 | } // namespace |
| 38 | |
| 39 | // A "weak" definition for cctz_extension::zone_info_source_factory. |
| 40 | // The user may override this with their own "strong" definition (see |
| 41 | // zone_info_source.h). |
| 42 | #if defined(_MSC_VER) |
| 43 | extern ZoneInfoSourceFactory zone_info_source_factory; |
| 44 | extern ZoneInfoSourceFactory default_factory; |
| 45 | ZoneInfoSourceFactory default_factory = DefaultFactory; |
| 46 | #if defined(_M_IX86) |
| 47 | #pragma comment( \ |
| 48 | linker, \ |
| 49 | "/alternatename:?zone_info_source_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZA=?default_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZA") |
| 50 | #elif defined(_M_IA_64) || defined(_M_AMD64) |
| 51 | #pragma comment( \ |
| 52 | linker, \ |
| 53 | "/alternatename:?zone_info_source_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZEA=?default_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZEA") |
| 54 | #else |
| 55 | #error Unsupported MSVC platform |
| 56 | #endif // _MSC_VER |
| 57 | #else |
| 58 | ZoneInfoSourceFactory zone_info_source_factory |
| 59 | __attribute__((weak)) = DefaultFactory; |
| 60 | #endif |
| 61 | |
| 62 | } // namespace cctz_extension |
| 63 | |