📄 chset.hpp
字号:
}
static void detach_clear(rep*& ptr)
{
if (ptr->uc > 1)
{
rep* t = new rep;
--ptr->uc;
ptr = t;
}
else
{
ptr->rr.clear();
}
}
#if !((defined (__GNUC__)) || defined (BOOST_MSVC))
private: // I can't get G++ to make impl::chset_converter a friend
#endif // of this class. Complains that rep_of is private.
rep& operator=(rep const& rhs); // No definition
static rep*& rep_of(chset<CharT>& set) { return set.ptr;}
static rep const* rep_of(chset<CharT> const& set) { return set.ptr;}
#if !((defined (__GNUC__)) || defined (BOOST_MSVC))
friend chset<CharT> operator|<>(chset<CharT> const&, chset<CharT> const&);
friend chset<CharT> operator-<>(chset<CharT> const&, chset<CharT> const&);
friend class impl::chset_converter;
#endif
unsigned uc;
impl::range_run<CharT> rr;
};
private:
rep* ptr;
friend class rep;
};
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
struct chset_converter
{
template <typename CharTA, typename CharTB>
void
static convert(chset<CharTA>& dest, chset<CharTB> const& src)
{
typedef typename std::vector<impl::range<CharTA> > vector_a;
typedef typename std::vector<impl::range<CharTB> > const vector_b;
typedef typename chset<CharTA>::rep rep_a;
typedef typename chset<CharTB>::rep rep_b;
typedef typename impl::range<CharTA> range;
rep_b const* sp = rep_b::rep_of(src);
vector_a& ss = rep_a::rep_of(dest)->rr.run;
for (typename vector_b::const_iterator iter = sp->begin();
iter != sp->end(); ++iter)
ss.push_back(range(iter->first, iter->last));
}
};
//////////////////////////////////////////////////////////////////////////
namespace chset_converter_namespace
{
template <typename CharTA, typename CharTB>
void convert(chset<CharTA>& dest, chset<CharTB> const& src)
{
impl::chset_converter::convert(dest,src);
}
}
} //end namespace impl
///////////////////////////////////////////////////////////////////////////////
//
// range <--> chset free operators
//
// Where a is a chset and b is a range, and vice-versa, implements:
//
// a | b, a & b, a - b, a ^ b
//
// Where a is a range, implements:
//
// ~a
//
///////////////////////////////////////////////////////////////////////////////
template <typename CharT>
chset<CharT>
operator~(range<CharT> const& a);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(chset<CharT> const& a, range<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(chset<CharT> const& a, range<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(chset<CharT> const& a, range<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(chset<CharT> const& a, range<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(range<CharT> const& a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(range<CharT> const& a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(range<CharT> const& a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(range<CharT> const& a, chset<CharT> const& b);
///////////////////////////////////////////////////////////////////////////////
//
// chlit <--> chset free operators
//
// Where a is a chset and b is a chlit, and vice-versa, implements:
//
// a | b, a & b, a - b, a ^ b
//
// Where a is a chlit, implements:
//
// ~a
//
///////////////////////////////////////////////////////////////////////////////
template <typename CharT>
chset<CharT>
operator~(chlit<CharT> const& a);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(chset<CharT> const& a, chlit<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(chset<CharT> const& a, chlit<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(chset<CharT> const& a, chlit<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(chset<CharT> const& a, chlit<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(chlit<CharT> const& a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(chlit<CharT> const& a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(chlit<CharT> const& a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(chlit<CharT> const& a, chset<CharT> const& b);
///////////////////////////////////////////////////////////////////////////////
//
// literal primitives <--> chset free operators
//
// Where a is a chset and b is a literal primitive,
// and vice-versa, implements:
//
// a | b, a & b, a - b, a ^ b
//
///////////////////////////////////////////////////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(chset<CharT> const& a, CharT b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(chset<CharT> const& a, CharT b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(chset<CharT> const& a, CharT b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(chset<CharT> const& a, CharT b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(CharT a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(CharT a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(CharT a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(CharT a, chset<CharT> const& b);
///////////////////////////////////////////////////////////////////////////////
//
// anychar_ <--> chset free operators
//
// Where a is chset and b is a anychar_, and vice-versa, implements:
//
// a | b, a & b, a - b, a ^ b
//
// Where a is anychar, implements:
//
// ~a
//
///////////////////////////////////////////////////////////////////////////////
nothing_
operator~(anychar_ a);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(chset<CharT> const& a, anychar_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(chset<CharT> const& a, anychar_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(chset<CharT> const& a, anychar_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(chset<CharT> const& a, anychar_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(anychar_ a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(anychar_ a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(anychar_ a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(anychar_ a, chset<CharT> const& b);
///////////////////////////////////////////////////////////////////////////////
//
// nothing_ <--> chset free operators
//
// Where a is chset and b is nothing_, and vice-versa, implements:
//
// a | b, a & b, a - b, a ^ b
//
///////////////////////////////////////////////////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(chset<CharT> const& a, nothing_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(chset<CharT> const& a, nothing_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(chset<CharT> const& a, nothing_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(chset<CharT> const& a, nothing_ b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator|(nothing_ a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator&(nothing_ a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator-(nothing_ a, chset<CharT> const& b);
//////////////////////////////////
template <typename CharT>
chset<CharT>
operator^(nothing_ a, chset<CharT> const& b);
///////////////////////////////////////////////////////////////////////////////
} // namespace Spirit
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -