X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fcommon%2Fstrtol.h;fp=src%2Fceph%2Fsrc%2Fcommon%2Fstrtol.h;h=810273ebd23258e33ee40f3908919d1f938237b0;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/common/strtol.h b/src/ceph/src/common/strtol.h new file mode 100644 index 0000000..810273e --- /dev/null +++ b/src/ceph/src/common/strtol.h @@ -0,0 +1,58 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#ifndef CEPH_COMMON_STRTOL_H +#define CEPH_COMMON_STRTOL_H + +#include +extern "C" { +#include +} + +long long strict_strtoll(const char *str, int base, std::string *err); + +int strict_strtol(const char *str, int base, std::string *err); + +double strict_strtod(const char *str, std::string *err); + +float strict_strtof(const char *str, std::string *err); + +uint64_t strict_sistrtoll(const char *str, std::string *err); + +template +T strict_si_cast(const char *str, std::string *err); + +/* On enter buf points to the end of the buffer, e.g. where the least + * significant digit of the input number will be printed. Returns pointer to + * where the most significant digit were printed, including zero padding. + * Does NOT add zero at the end of buffer, this is responsibility of the caller. + */ +template +static inline +char* ritoa(T u, char *buf) +{ + static_assert(std::is_unsigned::value, "signed types are not supported"); + static_assert(base <= 16, "extend character map below to support higher bases"); + unsigned digits = 0; + while (u) { + *--buf = "0123456789abcdef"[u % base]; + u /= base; + digits++; + } + while (digits++ < width) + *--buf = '0'; + return buf; +} + +#endif