Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

88 lines (74 sloc) 2.273 kb
#ifndef COMMON_H
#define COMMON_H 1
#include <cassert>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <sys/time.h>
#include <memcached/engine.h>
#include "config.h"
#if defined(HAVE_MEMORY)
# include <memory>
#endif
#if defined(HAVE_TR1_MEMORY)
# include <tr1/memory>
#endif
#if defined(HAVE_BOOST_SHARED_PTR_HPP)
# include <boost/shared_ptr.hpp>
#endif
#if defined(SHARED_PTR_NAMESPACE)
using SHARED_PTR_NAMESPACE::shared_ptr;
#else
# error No shared pointer implementation found!
#endif
/* Linux' limits don't bring this in in c++ mode without doing weird
stuff. It's a known constant, so we'll just make it if we don't
have it. */
#ifndef UINT16_MAX
#define UINT16_MAX 65535
#endif /* UINT16_MAX */
// Stolen from http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
// Utility functions implemented in various modules.
extern EXTENSION_LOGGER_DESCRIPTOR *getLogger(void);
// Time handling functions
inline void advance_tv(struct timeval &tv, const double secs) {
double ip, fp;
fp = modf(secs, &ip);
int usec = static_cast<int>(fp * 1e6) + static_cast<int>(tv.tv_usec);
int quot = usec / 1000000;
int rem = usec % 1000000;
tv.tv_sec = static_cast<int>(ip) + tv.tv_sec + quot;
tv.tv_usec = rem;
}
inline bool less_tv(const struct timeval &tv1, const struct timeval &tv2) {
if (tv1.tv_sec == tv2.tv_sec) {
return tv1.tv_usec < tv2.tv_usec;
} else {
return tv1.tv_sec < tv2.tv_sec;
}
}
inline bool parseUint16(const char *in, uint16_t *out) {
assert(out != NULL);
errno = 0;
*out = 0;
char *endptr;
long num = strtol(in, &endptr, 10);
if (errno == ERANGE || num < 0 || num > UINT16_MAX) {
return false;
}
if (isspace(*endptr) || (*endptr == '\0' && endptr != in)) {
*out = static_cast<uint16_t>(num);
return true;
}
return false;
}
#endif /* COMMON_H */
Jump to Line
Something went wrong with that request. Please try again.