zone_info_source.h
Go to the documentation of this file.
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 // https://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 #ifndef ABSL_TIME_INTERNAL_CCTZ_ZONE_INFO_SOURCE_H_
16 #define ABSL_TIME_INTERNAL_CCTZ_ZONE_INFO_SOURCE_H_
17 
18 #include <cstddef>
19 #include <functional>
20 #include <memory>
21 #include <string>
22 
23 namespace absl {
24 namespace time_internal {
25 namespace cctz {
26 
27 // A stdio-like interface for providing zoneinfo data for a particular zone.
29  public:
30  virtual ~ZoneInfoSource();
31 
32  virtual std::size_t Read(void* ptr, std::size_t size) = 0; // like fread()
33  virtual int Skip(std::size_t offset) = 0; // like fseek()
34 
35  // Until the zoneinfo data supports versioning information, we provide
36  // a way for a ZoneInfoSource to indicate it out-of-band. The default
37  // implementation returns an empty std::string.
38  virtual std::string Version() const;
39 };
40 
41 } // namespace cctz
42 } // namespace time_internal
43 } // namespace absl
44 
45 namespace absl {
46 namespace time_internal {
47 namespace cctz_extension {
48 
49 // A function-pointer type for a factory that returns a ZoneInfoSource
50 // given the name of a time zone and a fallback factory. Returns null
51 // when the data for the named zone cannot be found.
53  std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource> (*)(
54  const std::string&,
55  const std::function<std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource>(
56  const std::string&)>&);
57 
58 // The user can control the mapping of zone names to zoneinfo data by
59 // providing a definition for cctz_extension::zone_info_source_factory.
60 // For example, given functions my_factory() and my_other_factory() that
61 // can return a ZoneInfoSource for a named zone, we could inject them into
62 // cctz::load_time_zone() with:
63 //
64 // namespace cctz_extension {
65 // namespace {
66 // std::unique_ptr<cctz::ZoneInfoSource> CustomFactory(
67 // const std::string& name,
68 // const std::function<std::unique_ptr<cctz::ZoneInfoSource>(
69 // const std::string& name)>& fallback_factory) {
70 // if (auto zip = my_factory(name)) return zip;
71 // if (auto zip = fallback_factory(name)) return zip;
72 // if (auto zip = my_other_factory(name)) return zip;
73 // return nullptr;
74 // }
75 // } // namespace
76 // ZoneInfoSourceFactory zone_info_source_factory = CustomFactory;
77 // } // namespace cctz_extension
78 //
79 // This might be used, say, to use zoneinfo data embedded in the program,
80 // or read from a (possibly compressed) file archive, or both.
81 //
82 // cctz_extension::zone_info_source_factory() will be called:
83 // (1) from the same thread as the cctz::load_time_zone() call,
84 // (2) only once for any zone name, and
85 // (3) serially (i.e., no concurrent execution).
86 //
87 // The fallback factory obtains zoneinfo data by reading files in ${TZDIR},
88 // and it is used automatically when no zone_info_source_factory definition
89 // is linked into the program.
91 
92 } // namespace cctz_extension
93 } // namespace time_internal
94 } // namespace absl
95 
96 #endif // ABSL_TIME_INTERNAL_CCTZ_ZONE_INFO_SOURCE_H_
ZoneInfoSourceFactory zone_info_source_factory
virtual std::string Version() const
virtual int Skip(std::size_t offset)=0
Definition: algorithm.h:29
char * ptr
virtual std::size_t Read(void *ptr, std::size_t size)=0
uintptr_t size
std::unique_ptr< absl::time_internal::cctz::ZoneInfoSource >(*)(const std::string &, const std::function< std::unique_ptr< absl::time_internal::cctz::ZoneInfoSource >(const std::string &)> &) ZoneInfoSourceFactory


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:38