Skip to content

Commit

Permalink
optimize stream operator
Browse files Browse the repository at this point in the history
Signed-off-by: Ze Gan <[email protected]>
  • Loading branch information
Pterosaur committed Dec 28, 2020
1 parent a7f5acd commit 45af9c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
3 changes: 1 addition & 2 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ libswsscommon_la_SOURCES = \
subscriberstatetable.cpp \
timestamp.cpp \
warm_restart.cpp \
redisutility.cpp \
boolean.cpp
redisutility.cpp

libswsscommon_la_CXXFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(LIBNL_CFLAGS)
libswsscommon_la_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(LIBNL_CPPFLAGS)
Expand Down
34 changes: 0 additions & 34 deletions common/boolean.cpp

This file was deleted.

31 changes: 27 additions & 4 deletions common/boolean.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <iostream>
#include <ios>

namespace swss
{
Expand Down Expand Up @@ -28,12 +29,34 @@ class AlphaBoolean : public Boolean
}
};

std::ostream &operator<<(std::ostream &out, const Boolean &b);
static inline std::ostream &operator<<(std::ostream &out, const AlphaBoolean &b)
{
bool value = b;
out << std::boolalpha << value;
return out;
}

std::istream &operator>>(std::istream &in, Boolean &b);
static inline std::istream &operator>>(std::istream &in, AlphaBoolean &b)
{
bool value = false;
in >> std::boolalpha >> value;
b = value;
return in;
}

std::ostream &operator<<(std::ostream &out, const AlphaBoolean &b);
static inline std::ostream &operator<<(std::ostream &out, const Boolean &b)
{
bool value = b;
out << value;
return out;
}

std::istream &operator>>(std::istream &in, AlphaBoolean &b);
static inline std::istream &operator>>(std::istream &in, Boolean &b)
{
bool value = false;
in >> value;
b = value;
return in;
}

}

0 comments on commit 45af9c2

Please sign in to comment.