ListToOStream2.h
// ListToOStream2.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2008
#include "Ceda/cxUtils/ListToOStream.h"
@import "cxObject.h"
@import "IObject.h"
namespace ceda
{
@def mDefineStreamMixin(args,name,code) =
{
@def typedArgs =
{
@for ((t,a) in args)
{
t a,
}
}
@def argNames =
{
@for ((t,a) in args)
{
a,
}
}
@def mixin = name@@Mixin
@def mixin2 = const mixin<argNames Base>
template <typedArgs class Base>
class mixin : public Base {};
template <typedArgs class Base>
ceda::xostream& operator<<(ceda::xostream& os, mixin2& v)
{
code
return os;
}
template <typedArgs class Base>
mixin2& As@@name(const Base& b)
{
return (mixin2&) b;
}
}
mDefineStreamMixin(
[ (xchar,leftBracket), (xchar,rightBracket) ],
MyBracketed,
{
os << leftBracket << (const Base&) v << rightBracket;
})
mDefineStreamMixin(
[ (int,indent) ],
MyIndented,
{
Indenter indenter(os,indent);
os << (const Base&) v;
})
mDefineStreamMixin(
[ (xchar,delimiter), (EDelimiterPlacement,placement) ],
MyList,
{
WriteList<delimiter,placement>(os, v.begin(), v.end());
})
/*
It seems that only macros make it convenient to build helper functions like
AsSquareBracketedListWithLineFeeds. The problem is the need to specify the return type.
Unfortunately cxUtils doesn't have access to the macros.
*/
@def mAsSquareBracketed(x) = AsMyBracketed<'[',']'>(x)
@def mAsRoundBracketed(x) = AsMyBracketed<'(',')'>(x)
@def mAsCurlyBracketed(x) = AsMyBracketed<'{','}'>(x)
@def mAsIndented(x) = AsMyIndented<4>(x)
@def mAsCommaSeparatedList(x) = AsMyList<',',DELIMIT_BETWEEN>(x)
@def mAsLineFeedSeparatedList(x) = AsMyList<'\n',DELIMIT_AROUND>(x)
@def mAsSquareBracketedListWithLineFeeds(x) =
{
mAsSquareBracketed(mAsIndented(mAsLineFeedSeparatedList(x)))
}
} // namespace ceda