From: Mark Goldman <mgoldman@tresys.com>
To: selinux@tycho.nsa.gov
Subject: [POLICYREP] [Patch 1/2] Generalize an output function to make display easier.
Date: Thu, 16 Aug 2007 14:28:55 -0400 [thread overview]
Message-ID: <20070816183257.447285544@tresys.com> (raw)
In-Reply-To: 20070816182854.469714631@tresys.com
Generalize an output function to make display easier.
---
libpolicyrep/include/policyrep/policy_base.hpp | 39 36 + 3 - 0 !
libpolicyrep/src/policy_base.cpp | 22 4 + 18 - 0 !
2 files changed, 40 insertions(+), 21 deletions(-)
--- cpp-policyrep.orig/libpolicyrep/src/policy_base.cpp
+++ cpp-policyrep/libpolicyrep/src/policy_base.cpp
@@ -37,30 +37,16 @@ namespace policyrep
{
if (set.size() > 1)
o << "{ ";
- StringSet::const_iterator i;
- bool first = true;
- for (i = set.begin(); i != set.end(); ++i) {
- if (first)
- first = false;
- else
- o << " ";
- o << *i;
- }
+
+ output_container(o, set.begin(), set.end(), " ");
+
if (set.size() > 1)
o << " }";
}
void output_set_comma(std::ostream& o, const StringSet& set)
{
- StringSet::const_iterator i;
- bool first = true;
- for (i = set.begin(); i != set.end(); ++i) {
- if (first)
- first = false;
- else
- o << ", ";
- o << *i;
- }
+ output_container(o, set.begin(), set.end(), ", ");
}
std::ostream& operator<<(std::ostream& o, const Node& n)
--- cpp-policyrep.orig/libpolicyrep/include/policyrep/policy_base.hpp
+++ cpp-policyrep/libpolicyrep/include/policyrep/policy_base.hpp
@@ -8,11 +8,13 @@
#include <string>
#include <functional>
#include <ostream>
+#include <iterator>
#include <boost/shared_ptr.hpp>
#include <boost/iterator/iterator_facade.hpp>
namespace policyrep {
+ using std::string;
// Forward declarations
class Node;
@@ -34,6 +36,37 @@ namespace policyrep {
typedef boost::shared_ptr<StringVector> StringVectorPtr;
// Output (string output)
+ template<class iter>
+ void output_container(std::ostream& o, const iter& beg, const iter& end,
+ const string sep)
+ {
+ bool first = true;
+ for(iter i = beg; i != end; i++)
+ {
+ if(!first){
+ o << sep;
+ }
+ o << *i;
+ first = false;
+ }
+ }
+
+ template<class iter>
+ void bracket_output_container(std::ostream& o, const iter& beg,
+ const iter& end, const string sep,
+ const string pre, const string post)
+ {
+ iter temp = beg;
+ ++temp;
+ if(temp != end){
+ o << pre;
+ }
+ output_container(o, beg, end, sep);
+ if(temp != end){
+ o << post;
+ }
+ }
+
std::ostream& operator<<(std::ostream& o, const Node& n);
void output_set_space(std::ostream& o, const StringSet& set);
@@ -149,10 +182,10 @@ namespace policyrep {
virtual void make_child(NodePtr node);
template<class T>
- void append_children(T begin, T end)
+ void append_children(T start, T finish)
{
- for (; begin != end; ++begin)
- append_child(*begin);
+ for (; start != finish; ++start)
+ append_child(*start);
}
virtual NodeVector& children();
--
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
next prev parent reply other threads:[~2007-08-16 18:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-16 18:28 [POLICYREP] [Patch 0/2] Add MLS support to policy rep branch Mark Goldman
2007-08-16 18:28 ` Mark Goldman [this message]
2007-08-16 18:28 ` [POLICYREP] [Patch 2/2] Add mls to the policy representation Mark Goldman
2007-09-04 18:55 ` [POLICYREP] [Patch 0/2] Add MLS support to policy rep branch Joshua Brindle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070816183257.447285544@tresys.com \
--to=mgoldman@tresys.com \
--cc=selinux@tycho.nsa.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.