summaryrefslogtreecommitdiff
path: root/util/goodies.h
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-01-15 10:17:11 -0500
committerAaron <aaron@10gen.com>2009-01-15 10:17:11 -0500
commit90d45238aa5fccb6dbdf0b40dfcf5823695d4643 (patch)
tree7a95e901512b890eb06309af2edd0da9c88b7279 /util/goodies.h
parent938c2c07a8032259527b8e9cbb6d0d12c7e8867a (diff)
downloadmongo-90d45238aa5fccb6dbdf0b40dfcf5823695d4643.tar.gz
Indent all lines within namespaces one level
Diffstat (limited to 'util/goodies.h')
-rw-r--r--util/goodies.h374
1 files changed, 187 insertions, 187 deletions
diff --git a/util/goodies.h b/util/goodies.h
index 3a9479d4106..040c2e0ed97 100644
--- a/util/goodies.h
+++ b/util/goodies.h
@@ -31,9 +31,9 @@ namespace mongo {
namespace mongo {
-inline pthread_t GetCurrentThreadId() {
- return pthread_self();
-}
+ inline pthread_t GetCurrentThreadId() {
+ return pthread_self();
+ }
} // namespace mongo
@@ -41,72 +41,72 @@ inline pthread_t GetCurrentThreadId() {
namespace mongo {
-/* use "addr2line -CFe <exe>" to parse. */
-inline void printStackTrace() {
- void *b[12];
- size_t size;
- char **strings;
- size_t i;
+ /* use "addr2line -CFe <exe>" to parse. */
+ inline void printStackTrace() {
+ void *b[12];
+ size_t size;
+ char **strings;
+ size_t i;
- size = backtrace(b, 12);
- strings = backtrace_symbols(b, size);
+ size = backtrace(b, 12);
+ strings = backtrace_symbols(b, size);
- for (i = 0; i < size; i++)
- cout << hex << b[i] << ' ';
- cout << '\n';
- for (i = 0; i < size; i++)
- cout << ' ' << strings[i] << '\n';
+ for (i = 0; i < size; i++)
+ cout << hex << b[i] << ' ';
+ cout << '\n';
+ for (i = 0; i < size; i++)
+ cout << ' ' << strings[i] << '\n';
- free (strings);
-}
+ free (strings);
+ }
#else
-inline void printStackTrace() { }
+ inline void printStackTrace() { }
#endif
-/* set to TRUE if we are exiting */
-extern bool goingAway;
+ /* set to TRUE if we are exiting */
+ extern bool goingAway;
-/* find the multimap member which matches a particular key and value.
+ /* find the multimap member which matches a particular key and value.
- note this can be slow if there are a lot with the same key.
-*/
-template<class C,class K,class V> inline typename C::iterator kv_find(C& c, const K& k,const V& v) {
- pair<typename C::iterator,typename C::iterator> p = c.equal_range(k);
-
- for ( typename C::iterator it=p.first; it!=p.second; ++it)
- if ( it->second == v )
- return it;
-
- return c.end();
-}
-
-bool isPrime(int n);
-int nextPrime(int n);
-
-inline void dumpmemory(const char *data, int len) {
- if ( len > 1024 )
- len = 1024;
- try {
- const char *q = data;
- const char *p = q;
- while ( len > 0 ) {
- for ( int i = 0; i < 16; i++ ) {
- if ( *p >= 32 && *p <= 126 )
- cout << *p;
- else
- cout << '.';
- p++;
+ note this can be slow if there are a lot with the same key.
+ */
+ template<class C,class K,class V> inline typename C::iterator kv_find(C& c, const K& k,const V& v) {
+ pair<typename C::iterator,typename C::iterator> p = c.equal_range(k);
+
+ for ( typename C::iterator it=p.first; it!=p.second; ++it)
+ if ( it->second == v )
+ return it;
+
+ return c.end();
+ }
+
+ bool isPrime(int n);
+ int nextPrime(int n);
+
+ inline void dumpmemory(const char *data, int len) {
+ if ( len > 1024 )
+ len = 1024;
+ try {
+ const char *q = data;
+ const char *p = q;
+ while ( len > 0 ) {
+ for ( int i = 0; i < 16; i++ ) {
+ if ( *p >= 32 && *p <= 126 )
+ cout << *p;
+ else
+ cout << '.';
+ p++;
+ }
+ cout << " ";
+ p -= 16;
+ for ( int i = 0; i < 16; i++ )
+ cout << (unsigned) ((unsigned char)*p++) << ' ';
+ cout << endl;
+ len -= 16;
}
- cout << " ";
- p -= 16;
- for ( int i = 0; i < 16; i++ )
- cout << (unsigned) ((unsigned char)*p++) << ' ';
- cout << endl;
- len -= 16;
+ } catch (...) {
}
- } catch (...) {
}
-}
#undef yassert
@@ -121,31 +121,31 @@ namespace mongo {
#define assert xassert
#define yassert 1
-struct WrappingInt {
- WrappingInt() {
- x = 0;
- }
- WrappingInt(unsigned z) : x(z) { }
- unsigned x;
- operator unsigned() const {
- return x;
- }
- WrappingInt& operator++() {
- x++;
- return *this;
- }
- static int diff(unsigned a, unsigned b) {
- return a-b;
- }
- bool operator<=(WrappingInt r) {
- // platform dependent
- int df = (r.x - x);
- return df >= 0;
- }
- bool operator>(WrappingInt r) {
- return !(r<=*this);
- }
-};
+ struct WrappingInt {
+ WrappingInt() {
+ x = 0;
+ }
+ WrappingInt(unsigned z) : x(z) { }
+ unsigned x;
+ operator unsigned() const {
+ return x;
+ }
+ WrappingInt& operator++() {
+ x++;
+ return *this;
+ }
+ static int diff(unsigned a, unsigned b) {
+ return a-b;
+ }
+ bool operator<=(WrappingInt r) {
+ // platform dependent
+ int df = (r.x - x);
+ return df >= 0;
+ }
+ bool operator>(WrappingInt r) {
+ return !(r<=*this);
+ }
+ };
} // namespace mongo
@@ -153,119 +153,119 @@ struct WrappingInt {
namespace mongo {
-inline void time_t_to_String(time_t t, char *buf) {
+ inline void time_t_to_String(time_t t, char *buf) {
#if defined(_WIN32)
- ctime_s(buf, 64, &t);
+ ctime_s(buf, 64, &t);
#else
- ctime_r(&t, buf);
+ ctime_r(&t, buf);
#endif
- buf[24] = 0; // don't want the \n
-}
+ buf[24] = 0; // don't want the \n
+ }
#define asctime _asctime_not_threadsafe_
#define gmtime _gmtime_not_threadsafe_
#define localtime _localtime_not_threadsafe_
#define ctime _ctime_is_not_threadsafe_
-inline void sleepsecs(int s) {
- boost::xtime xt;
- boost::xtime_get(&xt, boost::TIME_UTC);
- xt.sec += s;
- boost::thread::sleep(xt);
-}
-inline void sleepmillis(int s) {
- boost::xtime xt;
- boost::xtime_get(&xt, boost::TIME_UTC);
- xt.nsec += s * 1000000;
- boost::thread::sleep(xt);
-}
+ inline void sleepsecs(int s) {
+ boost::xtime xt;
+ boost::xtime_get(&xt, boost::TIME_UTC);
+ xt.sec += s;
+ boost::thread::sleep(xt);
+ }
+ inline void sleepmillis(int s) {
+ boost::xtime xt;
+ boost::xtime_get(&xt, boost::TIME_UTC);
+ xt.nsec += s * 1000000;
+ boost::thread::sleep(xt);
+ }
// note this wraps
-inline int tdiff(unsigned told, unsigned tnew) {
- return WrappingInt::diff(tnew, told);
-}
-inline unsigned curTimeMillis() {
- boost::xtime xt;
- boost::xtime_get(&xt, boost::TIME_UTC);
- unsigned t = xt.nsec / 1000000;
- return (xt.sec & 0xfffff) * 1000 + t;
-}
-
-inline unsigned long long jsTime() {
- boost::xtime xt;
- boost::xtime_get(&xt, boost::TIME_UTC);
- unsigned long long t = xt.nsec / 1000000;
- return ((unsigned long long) xt.sec * 1000) + t;
-}
-
-inline unsigned long long curTimeMicros64() {
- boost::xtime xt;
- boost::xtime_get(&xt, boost::TIME_UTC);
- unsigned long long t = xt.nsec / 1000;
- return (((unsigned long long) xt.sec) * 1000000) + t;
-}
-
-// measures up to 1024 seconds. or, 512 seconds with tdiff that is...
-inline unsigned curTimeMicros() {
- boost::xtime xt;
- boost::xtime_get(&xt, boost::TIME_UTC);
- unsigned t = xt.nsec / 1000;
- unsigned secs = xt.sec % 1024;
- return secs*1000000 + t;
-}
-using namespace boost;
-typedef boost::mutex::scoped_lock boostlock;
-
-// simple scoped timer
-class Timer {
-public:
- Timer() {
- reset();
+ inline int tdiff(unsigned told, unsigned tnew) {
+ return WrappingInt::diff(tnew, told);
}
- int millis() {
- return micros() / 1000;
+ inline unsigned curTimeMillis() {
+ boost::xtime xt;
+ boost::xtime_get(&xt, boost::TIME_UTC);
+ unsigned t = xt.nsec / 1000000;
+ return (xt.sec & 0xfffff) * 1000 + t;
}
- int micros() {
- unsigned n = curTimeMicros();
- return tdiff(old, n);
+
+ inline unsigned long long jsTime() {
+ boost::xtime xt;
+ boost::xtime_get(&xt, boost::TIME_UTC);
+ unsigned long long t = xt.nsec / 1000000;
+ return ((unsigned long long) xt.sec * 1000) + t;
}
- int micros(unsigned& n) { // returns cur time in addition to timer result
- n = curTimeMicros();
- return tdiff(old, n);
+
+ inline unsigned long long curTimeMicros64() {
+ boost::xtime xt;
+ boost::xtime_get(&xt, boost::TIME_UTC);
+ unsigned long long t = xt.nsec / 1000;
+ return (((unsigned long long) xt.sec) * 1000000) + t;
}
- void reset() {
- old = curTimeMicros();
+
+// measures up to 1024 seconds. or, 512 seconds with tdiff that is...
+ inline unsigned curTimeMicros() {
+ boost::xtime xt;
+ boost::xtime_get(&xt, boost::TIME_UTC);
+ unsigned t = xt.nsec / 1000;
+ unsigned secs = xt.sec % 1024;
+ return secs*1000000 + t;
}
-private:
- unsigned old;
-};
+ using namespace boost;
+ typedef boost::mutex::scoped_lock boostlock;
+
+// simple scoped timer
+ class Timer {
+ public:
+ Timer() {
+ reset();
+ }
+ int millis() {
+ return micros() / 1000;
+ }
+ int micros() {
+ unsigned n = curTimeMicros();
+ return tdiff(old, n);
+ }
+ int micros(unsigned& n) { // returns cur time in addition to timer result
+ n = curTimeMicros();
+ return tdiff(old, n);
+ }
+ void reset() {
+ old = curTimeMicros();
+ }
+ private:
+ unsigned old;
+ };
-/*
+ /*
-class DebugMutex : boost::noncopyable {
- friend class lock;
- boost::mutex m;
- int locked;
-public:
- DebugMutex() : locked(0); { }
- bool isLocked() { return locked; }
-};
+ class DebugMutex : boost::noncopyable {
+ friend class lock;
+ boost::mutex m;
+ int locked;
+ public:
+ DebugMutex() : locked(0); { }
+ bool isLocked() { return locked; }
+ };
-*/
+ */
//typedef boostlock lock;
-inline bool startsWith(const char *str, const char *prefix) {
- unsigned l = strlen(prefix);
- if ( strlen(str) < l ) return false;
- return strncmp(str, prefix, l) == 0;
-}
+ inline bool startsWith(const char *str, const char *prefix) {
+ unsigned l = strlen(prefix);
+ if ( strlen(str) < l ) return false;
+ return strncmp(str, prefix, l) == 0;
+ }
-inline bool endsWith(const char *p, const char *suffix) {
- int a = strlen(p);
- int b = strlen(suffix);
- if ( b > a ) return false;
- return strcmp(p + a - b, suffix) == 0;
-}
+ inline bool endsWith(const char *p, const char *suffix) {
+ int a = strlen(p);
+ int b = strlen(suffix);
+ if ( b > a ) return false;
+ return strcmp(p + a - b, suffix) == 0;
+ }
} // namespace mongo
@@ -273,22 +273,22 @@ inline bool endsWith(const char *p, const char *suffix) {
namespace mongo {
-inline unsigned long swapEndian(unsigned long x) {
- return
- ((x & 0xff) << 24) |
- ((x & 0xff00) << 8) |
- ((x & 0xff0000) >> 8) |
- ((x & 0xff000000) >> 24);
-}
+ inline unsigned long swapEndian(unsigned long x) {
+ return
+ ((x & 0xff) << 24) |
+ ((x & 0xff00) << 8) |
+ ((x & 0xff0000) >> 8) |
+ ((x & 0xff000000) >> 24);
+ }
#if defined(BOOST_LITTLE_ENDIAN)
-inline unsigned long fixEndian(unsigned long x) {
- return x;
-}
+ inline unsigned long fixEndian(unsigned long x) {
+ return x;
+ }
#else
-inline unsigned long fixEndian(unsigned long x) {
- return swapEndian(x);
-}
+ inline unsigned long fixEndian(unsigned long x) {
+ return swapEndian(x);
+ }
#endif