LogCabin
include/LogCabin/Util.h
Go to the documentation of this file.
00001 /* Copyright (c) 2015 Diego Ongaro
00002  *
00003  * Permission to use, copy, modify, and distribute this software for any
00004  * purpose with or without fee is hereby granted, provided that the above
00005  * copyright notice and this permission notice appear in all copies.
00006  *
00007  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
00008  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00009  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
00010  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00011  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00012  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00013  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00014  */
00015 
00016 /**
00017  * \file
00018  * This file declares helper functions that are useful in LogCabin clients.
00019  */
00020 
00021 #include <cstddef>
00022 #include <memory>
00023 #include <map>
00024 #include <mutex>
00025 #include <string>
00026 #include <vector>
00027 
00028 #ifndef LOGCABIN_INCLUDE_LOGCABIN_UTIL_H
00029 #define LOGCABIN_INCLUDE_LOGCABIN_UTIL_H
00030 
00031 namespace LogCabin {
00032 namespace Client {
00033 namespace Util {
00034 
00035 /**
00036  * Convert a human-readable description of a time duration into a number of
00037  * nanoseconds.
00038  * \param description
00039  *      Something like 10, 10s, -200ms, 3us, or -999ns. With no units, defaults
00040  *      to seconds. May be negative.
00041  *      Allowed units:
00042  *          ns, nanosecond(s),
00043  *          ms, millisecond(s),
00044  *          s, second(s),
00045  *          min, minute(s),
00046  *          h, hr, hour(s),
00047  *          d, day(s),
00048  *          w, wk, week(s),
00049  *          mo, month(s),
00050  *          y, yr, year(s).
00051  * \return
00052  *      Number of nanoseconds (may be negative, capped to the range of a signed
00053  *      64-bit integer).
00054  * \throw Client::InvalidArgumentException
00055  *      If description could not be parsed successfully.
00056  * \warning
00057  *      This function is subject to change. It is not subject to the versioning
00058  *      requirements of LogCabin's public API.
00059  */
00060 int64_t parseSignedDuration(const std::string& description);
00061 
00062 /**
00063  * Convert a human-readable description of a time duration into a number of
00064  * nanoseconds.
00065  * \param description
00066  *      Something like 10, 10s, 200ms, 3us, or 999ns. With no units, defaults
00067  *      to seconds. May not be negative.
00068  *      Allowed units:
00069  *          ns, nanosecond(s),
00070  *          ms, millisecond(s),
00071  *          s, second(s),
00072  *          min, minute(s),
00073  *          h, hr, hour(s),
00074  *          d, day(s),
00075  *          w, wk, week(s),
00076  *          mo, month(s),
00077  *          y, yr, year(s).
00078  * \return
00079  *      Number of nanoseconds (will not be negative, capped to the range of a
00080  *      signed 64-bit integer on the high end).
00081  * \throw Client::InvalidArgumentException
00082  *      If description could not be parsed successfully.
00083  * \warning
00084  *      This function is subject to change. It is not subject to the versioning
00085  *      requirements of LogCabin's public API.
00086  */
00087 uint64_t parseNonNegativeDuration(const std::string& description);
00088 
00089 
00090 } // namespace LogCabin::Util
00091 } // namespace LogCabin::Client
00092 } // namespace LogCabin
00093 
00094 #endif /* LOGCABIN_INCLUDE_LOGCABIN_UTIL_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines