Skip to content

Commit

Permalink
Add Priority::Low and Priority::High
Browse files Browse the repository at this point in the history
Change-Id: Ia6a8e2adb9671ab585264e0b56871d9324056464
Reviewed-on: http://review.northscale.com:8080/45
Reviewed-by: Dustin Sallings <dustin@spy.net>
Tested-by: Dustin Sallings <dustin@spy.net>
  • Loading branch information
trondn authored and dustin committed May 11, 2010
1 parent 0f66fbe commit feb922c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -34,6 +34,7 @@
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/version.m4
/priority_test
/stamp-h1
Makefile
Makefile.in
6 changes: 5 additions & 1 deletion Makefile.am
Expand Up @@ -15,6 +15,7 @@ ep_la_SOURCES = \
kvstore.hh \
locks.hh \
mutex.hh \
priority.hh priority.cc \
sqlite-eval.hh sqlite-eval.cc \
sqlite-kvstore.cc sqlite-kvstore.hh \
sqlite-pst.hh sqlite-pst.cc \
Expand All @@ -28,11 +29,14 @@ ep_la_DEPENDENCIES = libsqlite3.la
libsqlite3_la_SOURCES = embedded/sqlite3.h embedded/sqlite3.c
libsqlite3_la_CFLAGS = $(AM_CFLAGS) ${NO_WERROR}

check_PROGRAMS=hash_table_test
check_PROGRAMS=hash_table_test priority_test
TESTS=${check_PROGRAMS}

hash_table_test_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir) ${NO_WERROR}
hash_table_test_SOURCES = t/hash_table_test.cc item.cc
hash_table_test_DEPENDENCIES = ep.hh item.hh

priority_test_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir) ${NO_WERROR}
priority_test_SOURCES = t/priority_test.cc priority.hh priority.cc

test: check-TESTS
5 changes: 5 additions & 0 deletions priority.cc
@@ -0,0 +1,5 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include "priority.hh"

const Priority Priority::Low("low");
const Priority Priority::High("high");
36 changes: 36 additions & 0 deletions priority.hh
@@ -0,0 +1,36 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#ifndef PRIORITY_HH
#define PRIORITY_HH

#include "common.hh"

#include <string>

class Priority {
public:
static const Priority Low;
static const Priority High;

bool operator==(const Priority &other) const {
return (&other == this);
}

bool operator<(const Priority &other) const {
return this == &Low;
}

bool operator>(const Priority &other) const {
return this == &High;
}

const std::string &toString() const {
return name;
}

private:
Priority(const char *nm) : name(nm) { };
std::string name;
DISALLOW_COPY_AND_ASSIGN(Priority);
};

#endif
19 changes: 19 additions & 0 deletions t/priority_test.cc
@@ -0,0 +1,19 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include "priority.hh"
#undef NDEBUG
#include <assert.h>

int main(int argc, char **argv) {
(void)argc; (void)argv;

assert(Priority::Low < Priority::High);
assert(!(Priority::High < Priority::Low));
assert(Priority::High > Priority::Low);
assert(!(Priority::Low > Priority::High));
assert(!(Priority::Low == Priority::High));
assert(!(Priority::High == Priority::Low));
assert(Priority::Low == Priority::Low);
assert(Priority::High == Priority::High);

return 0;
}

0 comments on commit feb922c

Please sign in to comment.