diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2010-01-14 15:54:06 +0000 |
|---|---|---|
| committer | Krzysztof Kosiński <tweenk.pl@gmail.com> | 2010-01-14 15:54:06 +0000 |
| commit | 4ffa8666045001bd3822db293ebb0b728b249492 (patch) | |
| tree | c4595e3c98a260bab48d37a342b3fdc4002fd6b6 /src/util | |
| parent | Do not append a segment when finishing an open path with right click (diff) | |
| parent | Re-enable snapping on release, for now. (diff) | |
| download | inkscape-4ffa8666045001bd3822db293ebb0b728b249492.tar.gz inkscape-4ffa8666045001bd3822db293ebb0b728b249492.zip | |
Merge GSoC 2009 node tool rewrite
(bzr r8976)
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/accumulators.h | 113 | ||||
| -rw-r--r-- | src/util/hash.h | 41 |
2 files changed, 154 insertions, 0 deletions
diff --git a/src/util/accumulators.h b/src/util/accumulators.h new file mode 100644 index 000000000..c627786b1 --- /dev/null +++ b/src/util/accumulators.h @@ -0,0 +1,113 @@ +/** @file + * Frequently used accumulators for use with libsigc++ + */ +/* Authors: + * Krzysztof Kosiński <tweenk.pl@gmail.com> + * + * Copyright (C) 2009 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_UTIL_ACCUMULATORS_H +#define SEEN_UTIL_ACCUMULATORS_H + +#include <iterator> + +namespace Inkscape { +namespace Util { + +/** + * Accumulator which evaluates slots in reverse connection order. + * The slot that was connected last is evaluated first. + */ +struct Reverse { + typedef void result_type; + template <typename T_iterator> + result_type operator()(T_iterator first, T_iterator last) const { + while (first != last) *(--last); + } +}; + +/** + * Accumulator type for interruptible signals. Slots return a boolean value; emission + * is stopped when true is returned from a slot. + */ +struct Interruptible { + typedef bool result_type; + template <typename T_iterator> + result_type operator()(T_iterator first, T_iterator last) const { + for (; first != last; ++first) + if (*first) return true; + return false; + } +}; + +/** + * Same as Interruptible, but the slots are called in reverse order of connection, + * e.g. the slot that was connected last is evaluated first. + */ +struct ReverseInterruptible { + typedef bool result_type; + template <typename T_iterator> + result_type operator()(T_iterator first, T_iterator last) const { + while (first != last) { + if (*(--last)) return true; + } + return false; + } +}; + +/** + * The template parameter specifies how many slots from the beginning of the list + * should be evaluated after other slots. Useful for signals which invoke other signals + * once complete. Undefined results if the signal does not have at least @c num_chained + * slots before first emission. + * + * For example, if template param = 3, the execution order is as follows: + * @verbatim + 8. 1. 2. 3. 4. 5. 6. 7. + S1 S2 S3 S4 S5 S6 S7 S8 @endverbatim + */ +template <unsigned num_chained = 1> +struct Chained { + typedef void result_type; + template <typename T_iterator> + result_type operator()(T_iterator first, T_iterator last) const { + T_iterator save_first = first; + // ARGH, iterator_traits is not defined for slot iterators! + //std::advance(first, num_chained); + for (unsigned i = 0; i < num_chained && first != last; ++i) ++first; + for (; first != last; ++first) *first; + for (unsigned i = 0; i < num_chained && save_first != last; ++i, ++save_first) + *save_first; + } +}; + +/** + * Executes a logical OR on the results from slots. + */ +struct LogicalOr { + typedef bool result_type; + template <typename T_iterator> + result_type operator()(T_iterator first, T_iterator last) const { + bool ret = false; + for (; first != last; ++first) ret |= *first; + return ret; + } +}; + +} // namespace Util +} // namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/util/hash.h b/src/util/hash.h new file mode 100644 index 000000000..d5abeff5a --- /dev/null +++ b/src/util/hash.h @@ -0,0 +1,41 @@ +/** @file + * Hash function for various things + */ +/* Authors: + * Krzysztof Kosiński <tweenk.pl@gmail.com> + * + * Copyright (C) 2009 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_UTIL_HASH_H +#define SEEN_UTIL_HASH_H + +#include <boost/shared_ptr.hpp> + +namespace std { +namespace tr1 { + +/** Hash function for Boost shared pointers */ +template <typename T> +struct hash< boost::shared_ptr<T> > : public std::unary_function<boost::shared_ptr<T>, size_t> { + size_t operator()(boost::shared_ptr<T> p) const { + return reinterpret_cast<size_t>(p.get()); + } +}; + +} // namespace tr1 +} // namespace std + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
