<commit_before>#ifndef VEXCL_REDUCTOR_HPP
#define VEXCL_REDUCTOR_HPP

/*
The MIT License

Copyright (c) 2012-2013 Denis Demidov <ddemidov@ksu.ru>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
 * \file   vexcl/reductor.hpp
 * \author Denis Demidov <ddemidov@ksu.ru>
 * \brief  Vector expression reduction.
 */

#include <vector>
#include <array>
#include <string>
#include <sstream>
#include <numeric>
#include <limits>

#include <vexcl/operations.hpp>

namespace vex {

/// Summation. Should be used as a template parameter for Reductor class.
struct SUM {
    /* In order to define a reduction kind for vex::Reductor, one should:
     *
     * 1. Define initial value (e.g. 0 for sums, 1 for products, plus-minus
     *    infinity for extrema):
     */
    template <typename T>
    static T initial() {
        return T();
    }

    /*
     * 2. Provide an OpenCL function that will be used on compute device to do
     *    incremental reductions. That is nested struct "function":
     */
    template <typename T>
    struct function : UserFunction<function<T>, T(T, T)> {
        static std::string body() { return "return prm1 + prm2;"; }
    };

    /*
     * 3. Provide a host-side function that will be used for final reduction of
     *    small result vector on host:
     */
    template <class Iterator>
    static typename std::iterator_traits<Iterator>::value_type
    reduce(Iterator begin, Iterator end) {
        return std::accumulate(begin, end,
                initial<typename std::iterator_traits<Iterator>::value_type>()
                );
    }
};

/// Maximum element. Should be used as a template parameter for Reductor class.
struct MAX {
    template <typename T>
    static T initial() {
        // Strictly speaking, this should fail for unsigned types.
        // But negating maximum possible unsigned value gives 0 on
        // 2s complement systems, so...
        return -std::numeric_limits<T>::max();
    }

    template <typename T>
    struct function : UserFunction<function<T>, T(T, T)> {
        static std::string body() { return "return max(prm1, prm2);"; }
    };

    template <class Iterator>
    static typename std::iterator_traits<Iterator>::value_type
    reduce(Iterator begin, Iterator end) {
        return *std::max_element(begin, end);
    }
};

/// Minimum element. Should be used as a template parameter for Reductor class.
struct MIN {
    template <typename T>
    static T initial() {
        return std::numeric_limits<T>::max();
    }

    template <typename T>
    struct function : UserFunction<function<T>, T(T, T)> {
        static std::string body() { return "return min(prm1, prm2);"; }
    };

    template <class Iterator>
    static typename std::iterator_traits<Iterator>::value_type
    reduce(Iterator begin, Iterator end) {
        return *std::min_element(begin, end);
    }
};

/// Parallel reduction of arbitrary expression.
/**
 * Reduction uses small temporary buffer on each device present in the queue
 * parameter. One Reductor class for each reduction kind is enough per thread
 * of execution.
 */
template <typename real, class RDC>
class Reductor {
    public:
        /// Constructor.
        Reductor(const std::vector<backend::command_queue> &queue
#ifndef VEXCL_NO_STATIC_CONTEXT_CONSTRUCTORS
                = current_context().queue()
#endif
                );

        /// Compute reduction of a vector expression.
        template <class Expr>
#ifdef DOXYGEN
        real
#else
        typename std::enable_if<
            boost::proto::matches<Expr, vector_expr_grammar>::value,
            real
        >::type
#endif
        operator()(const Expr &expr) const;

        /// Compute reduction of a multivector expression.
        template <class Expr>
#ifdef DOXYGEN
        std::array<real, N>
#else
        typename std::enable_if<
            boost::proto::matches<Expr, multivector_expr_grammar>::value &&
            !boost::proto::matches<Expr, vector_expr_grammar>::value,
            std::array<real, std::result_of<traits::multiex_dimension(Expr)>::type::value>
        >::type
#endif
        operator()(const Expr &expr) const;
    private:
        const std::vector<backend::command_queue> &queue;
        std::vector<size_t> idx;
        std::vector< backend::device_vector<real> > dbuf;

        mutable std::vector<real> hbuf;

        template <size_t I, size_t N, class Expr>
        typename std::enable_if<I == N, void>::type
        assign_subexpressions(std::array<real, N> &, const Expr &) const
        { }

        template <size_t I, size_t N, class Expr>
        typename std::enable_if<I < N, void>::type
        assign_subexpressions(std::array<real, N> &result, const Expr &expr) const
        {
            result[I] = (*this)(detail::extract_subexpression<I>()(expr));

            assign_subexpressions<I + 1, N, Expr>(result, expr);
        }
};

#ifndef DOXYGEN
template <typename real, class RDC>
Reductor<real,RDC>::Reductor(const std::vector<backend::command_queue> &queue)
    : queue(queue)
{
    idx.reserve(queue.size() + 1);
    idx.push_back(0);

    for(auto q = queue.begin(); q != queue.end(); q++) {
        size_t bufsize = backend::kernel::num_workgroups(*q);
        idx.push_back(idx.back() + bufsize);

        dbuf.push_back(backend::device_vector<real>(*q, bufsize));
    }

    hbuf.resize(idx.back());
}

template <typename real, class RDC> template <class Expr>
typename std::enable_if<
    boost::proto::matches<Expr, vector_expr_grammar>::value,
    real
>::type
Reductor<real,RDC>::operator()(const Expr &expr) const {
    using namespace detail;

    static kernel_cache cache;

    get_expression_properties prop;
    extract_terminals()(expr, prop);

    // Sometimes the expression only knows its size:
    if (prop.size && prop.part.empty())
        prop.part = vex::partition(prop.size, queue);

    for(unsigned d = 0; d < queue.size(); ++d) {
        auto key    = backend::cache_key(queue[d]);
        auto kernel = cache.find(key);

        backend::select_context(queue[d]);

        if (kernel == cache.end()) {
            backend::source_generator source(queue[d]);

            typedef typename RDC::template function<real> fun;
            fun::define(source, "reduce_operation");

            output_terminal_preamble termpream(source, queue[d], "prm", empty_state());
            boost::proto::eval(boost::proto::as_child(expr),  termpream);

            source.kernel("vexcl_reductor_kernel")
                .open("(").parameter<size_t>("n");

            extract_terminals()( expr, declare_expression_parameter(source, queue[d], "prm", empty_state()) );

            source
                .template parameter< global_ptr<real> >("g_odata")
                .template smem_parameter<real>()
                .close(")");

#define VEXCL_INCREMENT_MY_SUM                                                 \
  {                                                                            \
    output_local_preamble loc_init(source, queue[d], "prm", empty_state());    \
    boost::proto::eval(expr, loc_init);                                        \
    vector_expr_context expr_ctx(source, queue[d], "prm", empty_state());      \
    source.new_line() << "mySum = reduce_operation(mySum, ";                   \
    boost::proto::eval(expr, expr_ctx);                                        \
    source << ");";                                                            \
  }

            source.open("{");
            source.smem_declaration<real>();
            source.new_line() << type_name< shared_ptr<real> >() << " sdata = smem;";

            if ( backend::is_cpu(queue[d]) ) {
                source.new_line() << "size_t grid_size  = ";
                source.global_size(0) << ";";
                source.new_line() << "size_t chunk_size = (n + grid_size - 1) / grid_size;";
                source.new_line() << "size_t chunk_id   = ";
                source.global_id(0) << ";";
                source.new_line() << "size_t start      = min(n, chunk_size * chunk_id);";
                source.new_line() << "size_t stop       = min(n, chunk_size * (chunk_id + 1));";
                source.new_line() << type_name<real>() << " mySum = " << RDC::template initial<real>() << ";";
                source.new_line() << "for (size_t idx = start; idx < stop; idx++)";
                source.open("{");
                VEXCL_INCREMENT_MY_SUM
                source.close("}");
                source.new_line() << "g_odata[";
                source.group_id(0) << "] = mySum;";
                source.close("}");

                backend::kernel krn(queue[d], source.str(), "vexcl_reductor_kernel");
                kernel = cache.insert(std::make_pair(key, krn)).first;
            } else {
                source.new_line() << "size_t tid = ";
                source.local_id(0) << ";";
                source.new_line() << "size_t block_size = ";
                source.local_size(0) << ";";
                source.new_line() << type_name<real>() << " mySum = " << RDC::template initial<real>() << ";";

                source.grid_stride_loop().open("{");
                VEXCL_INCREMENT_MY_SUM
                source.close("}");
                source.new_line() << "sdata[tid] = mySum;";
                source.new_line().barrier();
                for(unsigned bs = 512; bs > 32; bs /= 2) {
                    source.new_line() << "if (block_size >= " << bs * 2 << ")";
                    source.open("{").new_line() << "if (tid < " << bs << ") "
                        "{ sdata[tid] = mySum = reduce_operation(mySum, sdata[tid + " << bs << "]); }";
                    source.new_line().barrier().close("}");
                }
                source.new_line() << "if (tid < 32)";
                source.open("{");
                source.new_line() << "volatile " << type_name< shared_ptr<real> >() << " smem = sdata;";
                for(unsigned bs = 32; bs > 0; bs /= 2) {
                    source.new_line() << "if (block_size >= " << 2 * bs << ") "
                        "{ smem[tid] = mySum = reduce_operation(mySum, smem[tid + " << bs << "]); }";
                }
                source.close("}");
                source.new_line() << "if (tid == 0) g_odata[";
                source.group_id(0) << "] = sdata[0];";
                source.close("}");

                backend::kernel krn(queue[d], source.str(), "vexcl_reductor_kernel", sizeof(real));
                kernel = cache.insert(std::make_pair(key, krn)).first;
            }
        }

#undef VEXCL_INCREMENT_MY_SUM

        if (size_t psize = prop.part_size(d)) {
            kernel->second.push_arg(psize);

            extract_terminals()(
                    expr,
                    set_expression_argument(kernel->second, d, prop.part_start(d), empty_state())
                    );

            kernel->second.push_arg(dbuf[d]);
            kernel->second.set_smem([](size_t wgs){ return wgs * sizeof(real); });

            kernel->second(queue[d]);
        }
    }

    std::fill(hbuf.begin(), hbuf.end(), RDC::template initial<real>());

    for(unsigned d = 0; d < queue.size(); d++) {
        if (prop.part_size(d))
            dbuf[d].read(queue[d], 0, idx[d + 1] - idx[d], &hbuf[idx[d]]);
    }

    for(unsigned d = 0; d < queue.size(); d++)
        if (prop.part_size(d)) queue[d].finish();

    return RDC::reduce(hbuf.begin(), hbuf.end());
}

template <typename real, class RDC> template <class Expr>
typename std::enable_if<
    boost::proto::matches<Expr, multivector_expr_grammar>::value &&
    !boost::proto::matches<Expr, vector_expr_grammar>::value,
    std::array<real, std::result_of<traits::multiex_dimension(Expr)>::type::value>
>::type
Reductor<real,RDC>::operator()(const Expr &expr) const {
    const size_t dim = std::result_of<traits::multiex_dimension(Expr)>::type::value;
    std::array<real, dim> result;

    assign_subexpressions<0, dim, Expr>(result, expr);

    return result;
}
#endif

/// Returns a reference to a static instance of vex::Reductor<T,R>
template <typename T, class R>
const vex::Reductor<T, R>& get_reductor(const std::vector<backend::command_queue> &queue)
{
    // We will hold one static reductor per set of queues (or, rather, contexts):
    static std::map< std::vector<backend::kernel_cache_key>, vex::Reductor<T, R> > cache;

    // Extract OpenCL context handles from command queues:
    std::vector<backend::kernel_cache_key> ctx;
    ctx.reserve(queue.size());
    for(auto q = queue.begin(); q != queue.end(); ++q)
        ctx.push_back( backend::cache_key(*q) );

    // See if there is suitable instance of reductor already:
    auto r = cache.find(ctx);

    // If not, create new instance and move it to the cache.
    if (r == cache.end())
        r = cache.insert( std::make_pair(
                    std::move(ctx), vex::Reductor<T, R>(queue)
                    ) ).first;

    return r->second;
}

} // namespace vex

#endif
<commit_msg>Fixed a minor bug in vex::Reductor<commit_after>#ifndef VEXCL_REDUCTOR_HPP
#define VEXCL_REDUCTOR_HPP

/*
The MIT License

Copyright (c) 2012-2013 Denis Demidov <ddemidov@ksu.ru>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
 * \file   vexcl/reductor.hpp
 * \author Denis Demidov <ddemidov@ksu.ru>
 * \brief  Vector expression reduction.
 */

#include <vector>
#include <array>
#include <string>
#include <sstream>
#include <numeric>
#include <limits>

#include <vexcl/operations.hpp>

namespace vex {

/// Summation. Should be used as a template parameter for Reductor class.
struct SUM {
    /* In order to define a reduction kind for vex::Reductor, one should:
     *
     * 1. Define initial value (e.g. 0 for sums, 1 for products, plus-minus
     *    infinity for extrema):
     */
    template <typename T>
    static T initial() {
        return T();
    }

    /*
     * 2. Provide an OpenCL function that will be used on compute device to do
     *    incremental reductions. That is nested struct "function":
     */
    template <typename T>
    struct function : UserFunction<function<T>, T(T, T)> {
        static std::string body() { return "return prm1 + prm2;"; }
    };

    /*
     * 3. Provide a host-side function that will be used for final reduction of
     *    small result vector on host:
     */
    template <class Iterator>
    static typename std::iterator_traits<Iterator>::value_type
    reduce(Iterator begin, Iterator end) {
        return std::accumulate(begin, end,
                initial<typename std::iterator_traits<Iterator>::value_type>()
                );
    }
};

/// Maximum element. Should be used as a template parameter for Reductor class.
struct MAX {
    template <typename T>
    static T initial() {
        if (std::is_integral<T>::value && !std::is_signed<T>::value)
            return static_cast<T>(0);
        else
            return -std::numeric_limits<T>::max();
    }

    template <typename T>
    struct function : UserFunction<function<T>, T(T, T)> {
        static std::string body() { return "return max(prm1, prm2);"; }
    };

    template <class Iterator>
    static typename std::iterator_traits<Iterator>::value_type
    reduce(Iterator begin, Iterator end) {
        return *std::max_element(begin, end);
    }
};

/// Minimum element. Should be used as a template parameter for Reductor class.
struct MIN {
    template <typename T>
    static T initial() {
        return std::numeric_limits<T>::max();
    }

    template <typename T>
    struct function : UserFunction<function<T>, T(T, T)> {
        static std::string body() { return "return min(prm1, prm2);"; }
    };

    template <class Iterator>
    static typename std::iterator_traits<Iterator>::value_type
    reduce(Iterator begin, Iterator end) {
        return *std::min_element(begin, end);
    }
};

/// Parallel reduction of arbitrary expression.
/**
 * Reduction uses small temporary buffer on each device present in the queue
 * parameter. One Reductor class for each reduction kind is enough per thread
 * of execution.
 */
template <typename real, class RDC>
class Reductor {
    public:
        /// Constructor.
        Reductor(const std::vector<backend::command_queue> &queue
#ifndef VEXCL_NO_STATIC_CONTEXT_CONSTRUCTORS
                = current_context().queue()
#endif
                );

        /// Compute reduction of a vector expression.
        template <class Expr>
#ifdef DOXYGEN
        real
#else
        typename std::enable_if<
            boost::proto::matches<Expr, vector_expr_grammar>::value,
            real
        >::type
#endif
        operator()(const Expr &expr) const;

        /// Compute reduction of a multivector expression.
        template <class Expr>
#ifdef DOXYGEN
        std::array<real, N>
#else
        typename std::enable_if<
            boost::proto::matches<Expr, multivector_expr_grammar>::value &&
            !boost::proto::matches<Expr, vector_expr_grammar>::value,
            std::array<real, std::result_of<traits::multiex_dimension(Expr)>::type::value>
        >::type
#endif
        operator()(const Expr &expr) const;
    private:
        const std::vector<backend::command_queue> &queue;
        std::vector<size_t> idx;
        std::vector< backend::device_vector<real> > dbuf;

        mutable std::vector<real> hbuf;

        template <size_t I, size_t N, class Expr>
        typename std::enable_if<I == N, void>::type
        assign_subexpressions(std::array<real, N> &, const Expr &) const
        { }

        template <size_t I, size_t N, class Expr>
        typename std::enable_if<I < N, void>::type
        assign_subexpressions(std::array<real, N> &result, const Expr &expr) const
        {
            result[I] = (*this)(detail::extract_subexpression<I>()(expr));

            assign_subexpressions<I + 1, N, Expr>(result, expr);
        }
};

#ifndef DOXYGEN
template <typename real, class RDC>
Reductor<real,RDC>::Reductor(const std::vector<backend::command_queue> &queue)
    : queue(queue)
{
    idx.reserve(queue.size() + 1);
    idx.push_back(0);

    for(auto q = queue.begin(); q != queue.end(); q++) {
        size_t bufsize = backend::kernel::num_workgroups(*q);
        idx.push_back(idx.back() + bufsize);

        dbuf.push_back(backend::device_vector<real>(*q, bufsize));
    }

    hbuf.resize(idx.back());
}

template <typename real, class RDC> template <class Expr>
typename std::enable_if<
    boost::proto::matches<Expr, vector_expr_grammar>::value,
    real
>::type
Reductor<real,RDC>::operator()(const Expr &expr) const {
    using namespace detail;

    static kernel_cache cache;

    get_expression_properties prop;
    extract_terminals()(expr, prop);

    // If expression is of zero size, then there is nothing to do. Hurray!
    if (prop.size == 0) return RDC::template initial<real>();

    // Sometimes the expression only knows its size:
    if (prop.size && prop.part.empty())
        prop.part = vex::partition(prop.size, queue);

    for(unsigned d = 0; d < queue.size(); ++d) {
        auto key    = backend::cache_key(queue[d]);
        auto kernel = cache.find(key);

        backend::select_context(queue[d]);

        if (kernel == cache.end()) {
            backend::source_generator source(queue[d]);

            typedef typename RDC::template function<real> fun;
            fun::define(source, "reduce_operation");

            output_terminal_preamble termpream(source, queue[d], "prm", empty_state());
            boost::proto::eval(boost::proto::as_child(expr),  termpream);

            source.kernel("vexcl_reductor_kernel")
                .open("(").parameter<size_t>("n");

            extract_terminals()( expr, declare_expression_parameter(source, queue[d], "prm", empty_state()) );

            source
                .template parameter< global_ptr<real> >("g_odata")
                .template smem_parameter<real>()
                .close(")");

#define VEXCL_INCREMENT_MY_SUM                                                 \
  {                                                                            \
    output_local_preamble loc_init(source, queue[d], "prm", empty_state());    \
    boost::proto::eval(expr, loc_init);                                        \
    vector_expr_context expr_ctx(source, queue[d], "prm", empty_state());      \
    source.new_line() << "mySum = reduce_operation(mySum, ";                   \
    boost::proto::eval(expr, expr_ctx);                                        \
    source << ");";                                                            \
  }

            source.open("{");
            source.smem_declaration<real>();
            source.new_line() << type_name< shared_ptr<real> >() << " sdata = smem;";

            if ( backend::is_cpu(queue[d]) ) {
                source.new_line() << "size_t grid_size  = ";
                source.global_size(0) << ";";
                source.new_line() << "size_t chunk_size = (n + grid_size - 1) / grid_size;";
                source.new_line() << "size_t chunk_id   = ";
                source.global_id(0) << ";";
                source.new_line() << "size_t start      = min(n, chunk_size * chunk_id);";
                source.new_line() << "size_t stop       = min(n, chunk_size * (chunk_id + 1));";
                source.new_line() << type_name<real>() << " mySum = " << RDC::template initial<real>() << ";";
                source.new_line() << "for (size_t idx = start; idx < stop; idx++)";
                source.open("{");
                VEXCL_INCREMENT_MY_SUM
                source.close("}");
                source.new_line() << "g_odata[";
                source.group_id(0) << "] = mySum;";
                source.close("}");

                backend::kernel krn(queue[d], source.str(), "vexcl_reductor_kernel");
                kernel = cache.insert(std::make_pair(key, krn)).first;
            } else {
                source.new_line() << "size_t tid = ";
                source.local_id(0) << ";";
                source.new_line() << "size_t block_size = ";
                source.local_size(0) << ";";
                source.new_line() << type_name<real>() << " mySum = " << RDC::template initial<real>() << ";";

                source.grid_stride_loop().open("{");
                VEXCL_INCREMENT_MY_SUM
                source.close("}");
                source.new_line() << "sdata[tid] = mySum;";
                source.new_line().barrier();
                for(unsigned bs = 512; bs > 32; bs /= 2) {
                    source.new_line() << "if (block_size >= " << bs * 2 << ")";
                    source.open("{").new_line() << "if (tid < " << bs << ") "
                        "{ sdata[tid] = mySum = reduce_operation(mySum, sdata[tid + " << bs << "]); }";
                    source.new_line().barrier().close("}");
                }
                source.new_line() << "if (tid < 32)";
                source.open("{");
                source.new_line() << "volatile " << type_name< shared_ptr<real> >() << " smem = sdata;";
                for(unsigned bs = 32; bs > 0; bs /= 2) {
                    source.new_line() << "if (block_size >= " << 2 * bs << ") "
                        "{ smem[tid] = mySum = reduce_operation(mySum, smem[tid + " << bs << "]); }";
                }
                source.close("}");
                source.new_line() << "if (tid == 0) g_odata[";
                source.group_id(0) << "] = sdata[0];";
                source.close("}");

                backend::kernel krn(queue[d], source.str(), "vexcl_reductor_kernel", sizeof(real));
                kernel = cache.insert(std::make_pair(key, krn)).first;
            }
        }

#undef VEXCL_INCREMENT_MY_SUM

        if (size_t psize = prop.part_size(d)) {
            kernel->second.push_arg(psize);

            extract_terminals()(
                    expr,
                    set_expression_argument(kernel->second, d, prop.part_start(d), empty_state())
                    );

            kernel->second.push_arg(dbuf[d]);
            kernel->second.set_smem([](size_t wgs){ return wgs * sizeof(real); });

            kernel->second(queue[d]);
        }
    }

    std::fill(hbuf.begin(), hbuf.end(), RDC::template initial<real>());

    for(unsigned d = 0; d < queue.size(); d++) {
        if (prop.part_size(d))
            dbuf[d].read(queue[d], 0, idx[d + 1] - idx[d], &hbuf[idx[d]]);
    }

    for(unsigned d = 0; d < queue.size(); d++)
        if (prop.part_size(d)) queue[d].finish();

    return RDC::reduce(hbuf.begin(), hbuf.end());
}

template <typename real, class RDC> template <class Expr>
typename std::enable_if<
    boost::proto::matches<Expr, multivector_expr_grammar>::value &&
    !boost::proto::matches<Expr, vector_expr_grammar>::value,
    std::array<real, std::result_of<traits::multiex_dimension(Expr)>::type::value>
>::type
Reductor<real,RDC>::operator()(const Expr &expr) const {
    const size_t dim = std::result_of<traits::multiex_dimension(Expr)>::type::value;
    std::array<real, dim> result;

    assign_subexpressions<0, dim, Expr>(result, expr);

    return result;
}
#endif

/// Returns a reference to a static instance of vex::Reductor<T,R>
template <typename T, class R>
const vex::Reductor<T, R>& get_reductor(const std::vector<backend::command_queue> &queue)
{
    // We will hold one static reductor per set of queues (or, rather, contexts):
    static std::map< std::vector<backend::kernel_cache_key>, vex::Reductor<T, R> > cache;

    // Extract OpenCL context handles from command queues:
    std::vector<backend::kernel_cache_key> ctx;
    ctx.reserve(queue.size());
    for(auto q = queue.begin(); q != queue.end(); ++q)
        ctx.push_back( backend::cache_key(*q) );

    // See if there is suitable instance of reductor already:
    auto r = cache.find(ctx);

    // If not, create new instance and move it to the cache.
    if (r == cache.end())
        r = cache.insert( std::make_pair(
                    std::move(ctx), vex::Reductor<T, R>(queue)
                    ) ).first;

    return r->second;
}

} // namespace vex

#endif
<|endoftext|>


<commit_before>#include "config.h"
#include "../context/fcontext.h"
#include "../scheduler/processer.h"
#include <string.h>
#include <stdarg.h>
#include <poll.h>
#if defined(LIBGO_SYS_Unix)
#include <sys/time.h>
#include <pthread.h>
#endif

#include "../scheduler/ref.h"
#include "../cls/co_local_storage.h"

namespace co {

#if ENABLE_HOOK
  #if defined(LIBGO_SYS_Linux) || defined(LIBGO_SYS_Windows)
    extern void initHook();
  #endif
#endif

static int staticInitialize()
{
    // scheduler
    TaskRefInit(Affinity);
    TaskRefInit(Location);
    TaskRefInit(DebugInfo);
//    TaskRefInit(SuspendId);

    // cls
    TaskRefInit(ClsMap);

#if ENABLE_HOOK
  #if defined(LIBGO_SYS_Linux)
    initHook();
  #endif
#endif
    return 0;
}

void LibgoInitialize()
{
    static int ignore = staticInitialize();
    (void)ignore;
}

std::mutex gDbgLock;

CoroutineOptions::CoroutineOptions()
    : protect_stack_page(StackTraits::GetProtectStackPageSize()),
    stack_malloc_fn(StackTraits::MallocFunc()),
    stack_free_fn(StackTraits::FreeFunc())
{
}

const char* BaseFile(const char* file)
{
    const char* p = strrchr(file, '/');
    if (p) return p + 1;

    p = strrchr(file, '\\');
    if (p) return p + 1;

    return file;
}

int GetCurrentProcessID()
{
#if defined(LIBGO_SYS_Unix)
    return getpid();
#else
    return 0;
#endif
}

int GetCurrentThreadID()
{
    auto proc = Processer::GetCurrentProcesser();
    return proc ? proc->Id() : -1;
}

int GetCurrentCoroID()
{
    Task* tk = Processer::GetCurrentTask();
    return tk ? tk->id_ : 0;
}

std::string GetCurrentTimeStr()
{
#if defined(LIBGO_SYS_Unix)
    struct tm local;
    struct timeval tv;
    gettimeofday(&tv, NULL);
    localtime_r(&tv.tv_sec, &local);
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d.%06d",
            local.tm_year+1900, local.tm_mon+1, local.tm_mday,
            local.tm_hour, local.tm_min, local.tm_sec, (int)tv.tv_usec);
    return std::string(buffer);
#else
    return std::string();
#endif
}

const char* PollEvent2Str(short int event)
{
    event &= POLLIN|POLLOUT|POLLERR;
    switch (event) {
        LIBGO_E2S_DEFINE(POLLIN);
        LIBGO_E2S_DEFINE(POLLOUT);
        LIBGO_E2S_DEFINE(POLLERR);
        LIBGO_E2S_DEFINE(POLLNVAL);
        LIBGO_E2S_DEFINE(POLLIN|POLLOUT);
        LIBGO_E2S_DEFINE(POLLIN|POLLERR);
        LIBGO_E2S_DEFINE(POLLOUT|POLLERR);
        LIBGO_E2S_DEFINE(POLLIN|POLLOUT|POLLERR);
        default:
        return "Zero";
    }
}
unsigned long NativeThreadID()
{
#if defined(LIBGO_SYS_Unix)
    return reinterpret_cast<unsigned long>(pthread_self());
#else
	return (unsigned long)GetCurrentThreadId();
#endif
}

std::string Format(const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    char buf[4096];
    int len = vsnprintf(buf, sizeof(buf), fmt, ap);
    va_end(ap);
    return std::string(buf, len);
}

std::string P(const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    char buf[4096];
    int len = vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
    buf[len] = '\n';
    buf[len+1] = '\0';
    va_end(ap);
    return std::string(buf, len + 1);
}
std::string P()
{
    return "\n";
}

} //namespace co
<commit_msg>fix initHook bug<commit_after>#include "config.h"
#include "../context/fcontext.h"
#include "../scheduler/processer.h"
#include <string.h>
#include <stdarg.h>
#include <poll.h>
#if defined(LIBGO_SYS_Unix)
#include <sys/time.h>
#include <pthread.h>
#endif

#include "../scheduler/ref.h"
#include "../cls/co_local_storage.h"

namespace co {

#if ENABLE_HOOK
  #if defined(LIBGO_SYS_Linux) || defined(LIBGO_SYS_Windows)
    extern void initHook();
  #endif
#endif

static int staticInitialize()
{
    // scheduler
    TaskRefInit(Affinity);
    TaskRefInit(Location);
    TaskRefInit(DebugInfo);
//    TaskRefInit(SuspendId);

    // cls
    TaskRefInit(ClsMap);

#if ENABLE_HOOK
  #if defined(LIBGO_SYS_Linux) || defined(LIBGO_SYS_Windows)
    initHook();
  #endif
#endif
    return 0;
}

void LibgoInitialize()
{
    static int ignore = staticInitialize();
    (void)ignore;
}

std::mutex gDbgLock;

CoroutineOptions::CoroutineOptions()
    : protect_stack_page(StackTraits::GetProtectStackPageSize()),
    stack_malloc_fn(StackTraits::MallocFunc()),
    stack_free_fn(StackTraits::FreeFunc())
{
}

const char* BaseFile(const char* file)
{
    const char* p = strrchr(file, '/');
    if (p) return p + 1;

    p = strrchr(file, '\\');
    if (p) return p + 1;

    return file;
}

int GetCurrentProcessID()
{
#if defined(LIBGO_SYS_Unix)
    return getpid();
#else
    return 0;
#endif
}

int GetCurrentThreadID()
{
    auto proc = Processer::GetCurrentProcesser();
    return proc ? proc->Id() : -1;
}

int GetCurrentCoroID()
{
    Task* tk = Processer::GetCurrentTask();
    return tk ? tk->id_ : 0;
}

std::string GetCurrentTimeStr()
{
#if defined(LIBGO_SYS_Unix)
    struct tm local;
    struct timeval tv;
    gettimeofday(&tv, NULL);
    localtime_r(&tv.tv_sec, &local);
    char buffer[128];
    snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d.%06d",
            local.tm_year+1900, local.tm_mon+1, local.tm_mday,
            local.tm_hour, local.tm_min, local.tm_sec, (int)tv.tv_usec);
    return std::string(buffer);
#else
    return std::string();
#endif
}

const char* PollEvent2Str(short int event)
{
    event &= POLLIN|POLLOUT|POLLERR;
    switch (event) {
        LIBGO_E2S_DEFINE(POLLIN);
        LIBGO_E2S_DEFINE(POLLOUT);
        LIBGO_E2S_DEFINE(POLLERR);
        LIBGO_E2S_DEFINE(POLLNVAL);
        LIBGO_E2S_DEFINE(POLLIN|POLLOUT);
        LIBGO_E2S_DEFINE(POLLIN|POLLERR);
        LIBGO_E2S_DEFINE(POLLOUT|POLLERR);
        LIBGO_E2S_DEFINE(POLLIN|POLLOUT|POLLERR);
        default:
        return "Zero";
    }
}
unsigned long NativeThreadID()
{
#if defined(LIBGO_SYS_Unix)
    return reinterpret_cast<unsigned long>(pthread_self());
#else
	return (unsigned long)GetCurrentThreadId();
#endif
}

std::string Format(const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    char buf[4096];
    int len = vsnprintf(buf, sizeof(buf), fmt, ap);
    va_end(ap);
    return std::string(buf, len);
}

std::string P(const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    char buf[4096];
    int len = vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
    buf[len] = '\n';
    buf[len+1] = '\0';
    va_end(ap);
    return std::string(buf, len + 1);
}
std::string P()
{
    return "\n";
}

} //namespace co
<|endoftext|>


<commit_before>/*
 *  ARC++
 *
 *  Copyright (c) 2007-2008 Steven Noonan.
 *
 *  Licensed under the New BSD License.
 *
 */

#include "universal_include.h"

#if defined ( TARGET_COMPILER_VC ) || defined ( TARGET_COMPILER_ICC )
#   pragma comment (lib, "unrar.lib")
#endif

#include "App/app.h"
#include "App/file_utils.h"
#include "App/resource.h"

#ifndef TARGET_OS_WINDOWS
inline static void strlwr ( char *_string )
{
    for ( char *p = _string; p && *p != '\0'; p++ )
        *p = tolower(*p);
}
#endif

Resource::Resource()
{
}

Resource::~Resource()
{
    Data::DArray<MemMappedFile *> *files = m_resourceFiles.ConvertToDArray();
    for ( size_t i = 0; i < files->size(); i++ )
    {
        if ( !files->valid ( i ) ) continue;
        delete files->get ( i );
    }
    delete files;
}

void Resource::ParseArchive ( const char *_dataFile, const char *_password )
{
    if (!FileExists( _dataFile))
        return;

    UncompressedArchive    *mainData = NULL;

    try
    {
        mainData = new UncompressedArchive(_dataFile, _password);
    }
    catch( ... )
    {
        return;
    }

    for (size_t i = 0; i < mainData->m_numFiles; ++i)
    {
        MemMappedFile *file = mainData->m_files[i];
        if (file->m_size > 0)
        {
            strlwr(file->m_filename);

            // Subsequent archives may override existing resources

            MemMappedFile *oldFile;
			bool exists = m_resourceFiles.find(file->m_filename, oldFile);
            if (exists) {
                m_resourceFiles.erase(file->m_filename);
                delete oldFile;
            }

            m_resourceFiles.insert(file->m_filename, file);
        }
    }

    delete mainData;
}

BinaryReader *Resource::GetBinaryReader ( char const *_filename )
{
    BinaryReader *reader = NULL;
    char fullFilename[256];

    // TODO: Implement moddability and themes, etc.
#if 0
    if ( m_modName )
    {
        sprintf( fullFilename, "%smods/%s/%s", g_app->GetProfileDirectory(), m_modName, _filename );
        if ( FileExists ( fullFilename) ) reader = new BinaryFileReader(fullFilename);
    }
#endif

    if ( !reader )
    {
        sprintf( fullFilename, "%s%s", g_app->GetApplicationSupportPath(), _filename );
        if ( FileExists ( fullFilename) ) reader = new BinaryFileReader(fullFilename);
    }

    if ( !reader )
    {
        if ( FileExists ( _filename ) ) reader = new BinaryFileReader(_filename);
    }

    if ( !reader )
    {
        MemMappedFile *mmfile = GetUncompressedFile(_filename);
        if (mmfile) reader = new BinaryDataReader(mmfile->m_data, mmfile->m_size, _filename);
    }

    return reader;
}

SDL_Surface *Resource::GetImage ( char const *_filename )
{
    char buffer[2048];
    MemMappedFile *memmap = NULL;
    SDL_Surface *surf = NULL;

    if ( !surf )
    {
        sprintf ( buffer, "%s%s", g_app->GetResourcePath(), _filename );
        surf = IMG_Load ( buffer );
    }

    memmap = GetUncompressedFile ( _filename );
    if ( !surf && memmap )
    {
        SDL_RWops *data = SDL_RWFromMem ( memmap->m_data, memmap->m_size );
        surf = IMG_Load_RW ( data, 0 );
        ARCReleaseAssert ( surf );
    }

    return surf;
}

#ifdef USE_SDLMIXER
Mix_Chunk *Resource::GetSound ( char const *_filename )
{
    char buffer[2048];
    MemMappedFile *memmap = NULL;
    Mix_Chunk *chunk = NULL;

    if ( !chunk )
    {
        sprintf ( buffer, "%s%s", g_app->GetResourcePath(), _filename );
        chunk = Mix_LoadWAV ( buffer );
    }

    memmap = GetUncompressedFile ( _filename );
    if ( !chunk && memmap )
    {
        SDL_RWops *data = SDL_RWFromMem ( memmap->m_data, memmap->m_size );
        chunk = Mix_LoadWAV_RW ( data, 0 );
    }

    return chunk;
}
#endif

TextReader *Resource::GetTextReader(char const *_filename)
{
    TextReader *reader = NULL;
    char fullFilename[256];

    fullFilename[0] = 0;

#if 0
    if( m_modName )
    {
        sprintf( fullFilename, "%smods/%s/%s", g_app->GetProfileDirectory(), m_modName, _filename );
        if( DoesFileExist(fullFilename) )
            reader = new TextFileReader(fullFilename);

#ifdef TARGET_OS_VISTA
        // The Oberon build bundles the Perdition mod
        if( !reader )
        {
            sprintf( fullFilename, "mods/%s/%s", m_modName, _filename );
            if( DoesFileExist(fullFilename) )
                reader = new TextFileReader(fullFilename);
        }
#endif
    }
#endif

    if( !reader )
    {
        sprintf( fullFilename, "data/%s", _filename );
        if ( FileExists ( fullFilename ) )
            reader = new TextFileReader(fullFilename);
    }

    if( !reader )
    {
        sprintf( fullFilename, "data/%s", _filename );
        MemMappedFile *mmfile = GetUncompressedFile(fullFilename);
        if ( mmfile )
            reader = new TextDataReader((char*)mmfile->m_data, mmfile->m_size, fullFilename);
    }

    return reader;
}

MemMappedFile *Resource::GetUncompressedFile ( char const *_filename )
{
	MemMappedFile *file;
	bool exists = m_resourceFiles.find ( _filename, file );
	return exists ? file : NULL;
}
<commit_msg>resource: load from disk if uncompressed file can't be found in RAM<commit_after>/*
 *  ARC++
 *
 *  Copyright (c) 2007-2008 Steven Noonan.
 *
 *  Licensed under the New BSD License.
 *
 */

#include "universal_include.h"

#if defined ( TARGET_COMPILER_VC ) || defined ( TARGET_COMPILER_ICC )
#   pragma comment (lib, "unrar.lib")
#endif

#include "App/app.h"
#include "App/file_utils.h"
#include "App/resource.h"

#ifndef TARGET_OS_WINDOWS
inline static void strlwr ( char *_string )
{
    for ( char *p = _string; p && *p != '\0'; p++ )
        *p = tolower(*p);
}
#endif

Resource::Resource()
{
}

Resource::~Resource()
{
    Data::DArray<MemMappedFile *> *files = m_resourceFiles.ConvertToDArray();
    for ( size_t i = 0; i < files->size(); i++ )
    {
        if ( !files->valid ( i ) ) continue;
        delete files->get ( i );
    }
    delete files;
}

void Resource::ParseArchive ( const char *_dataFile, const char *_password )
{
    if (!FileExists( _dataFile))
        return;

    UncompressedArchive    *mainData = NULL;

    try
    {
        mainData = new UncompressedArchive(_dataFile, _password);
    }
    catch( ... )
    {
        return;
    }

    for (size_t i = 0; i < mainData->m_numFiles; ++i)
    {
        MemMappedFile *file = mainData->m_files[i];
        if (file->m_size > 0)
        {
            strlwr(file->m_filename);

            // Subsequent archives may override existing resources

            MemMappedFile *oldFile;
			bool exists = m_resourceFiles.find(file->m_filename, oldFile);
            if (exists) {
                m_resourceFiles.erase(file->m_filename);
                delete oldFile;
            }

            m_resourceFiles.insert(file->m_filename, file);
        }
    }

    delete mainData;
}

BinaryReader *Resource::GetBinaryReader ( char const *_filename )
{
    BinaryReader *reader = NULL;
    char fullFilename[256];

    // TODO: Implement moddability and themes, etc.
#if 0
    if ( m_modName )
    {
        sprintf( fullFilename, "%smods/%s/%s", g_app->GetProfileDirectory(), m_modName, _filename );
        if ( FileExists ( fullFilename) ) reader = new BinaryFileReader(fullFilename);
    }
#endif

    if ( !reader )
    {
        sprintf( fullFilename, "%s%s", g_app->GetApplicationSupportPath(), _filename );
        if ( FileExists ( fullFilename) ) reader = new BinaryFileReader(fullFilename);
    }

    if ( !reader )
    {
        if ( FileExists ( _filename ) ) reader = new BinaryFileReader(_filename);
    }

    if ( !reader )
    {
        MemMappedFile *mmfile = GetUncompressedFile(_filename);
        if (mmfile) reader = new BinaryDataReader(mmfile->m_data, mmfile->m_size, _filename);
    }

    return reader;
}

SDL_Surface *Resource::GetImage ( char const *_filename )
{
    char buffer[2048];
    MemMappedFile *memmap = NULL;
    SDL_Surface *surf = NULL;

    if ( !surf )
    {
        sprintf ( buffer, "%s%s", g_app->GetResourcePath(), _filename );
        surf = IMG_Load ( buffer );
    }

    memmap = GetUncompressedFile ( _filename );
    if ( !surf && memmap )
    {
        SDL_RWops *data = SDL_RWFromMem ( memmap->m_data, memmap->m_size );
        surf = IMG_Load_RW ( data, 0 );
        ARCReleaseAssert ( surf );
    }

    return surf;
}

#ifdef USE_SDLMIXER
Mix_Chunk *Resource::GetSound ( char const *_filename )
{
    char buffer[2048];
    MemMappedFile *memmap = NULL;
    Mix_Chunk *chunk = NULL;

    if ( !chunk )
    {
        sprintf ( buffer, "%s%s", g_app->GetResourcePath(), _filename );
        chunk = Mix_LoadWAV ( buffer );
    }

    memmap = GetUncompressedFile ( _filename );
    if ( !chunk && memmap )
    {
        SDL_RWops *data = SDL_RWFromMem ( memmap->m_data, memmap->m_size );
        chunk = Mix_LoadWAV_RW ( data, 0 );
    }

    return chunk;
}
#endif

TextReader *Resource::GetTextReader(char const *_filename)
{
    TextReader *reader = NULL;
    char fullFilename[256];

    fullFilename[0] = 0;

#if 0
    if( m_modName )
    {
        sprintf( fullFilename, "%smods/%s/%s", g_app->GetProfileDirectory(), m_modName, _filename );
        if( DoesFileExist(fullFilename) )
            reader = new TextFileReader(fullFilename);

#ifdef TARGET_OS_VISTA
        // The Oberon build bundles the Perdition mod
        if( !reader )
        {
            sprintf( fullFilename, "mods/%s/%s", m_modName, _filename );
            if( DoesFileExist(fullFilename) )
                reader = new TextFileReader(fullFilename);
        }
#endif
    }
#endif

    if( !reader )
    {
        sprintf( fullFilename, "data/%s", _filename );
        if ( FileExists ( fullFilename ) )
            reader = new TextFileReader(fullFilename);
    }

    if( !reader )
    {
        sprintf( fullFilename, "data/%s", _filename );
        MemMappedFile *mmfile = GetUncompressedFile(fullFilename);
        if ( mmfile )
            reader = new TextDataReader((char*)mmfile->m_data, mmfile->m_size, fullFilename);
    }

    return reader;
}

MemMappedFile *Resource::GetUncompressedFile(char const *_filename)
{
	char           fullFilename[2048];

	MemMappedFile *file = NULL;

	if (!file) {
		sprintf(fullFilename, "%s%s", g_app->GetApplicationSupportPath(), _filename);
		if (FileExists(fullFilename)) {
			IO::FileReader *fr = new IO::FileReader();
			fr->Open(fullFilename);
			size_t          len = fr->Length();

			file = new MemMappedFile(fullFilename, len);
			fr->Read((char *)file->m_data, len, 0, len);
			fr->Close();
			delete fr;
		}
	}

	if (!file) {
		bool exists = m_resourceFiles.find(_filename, file);
		if (!exists) file = NULL;
	}

	return file;
}
<|endoftext|>


<commit_before>#include <boost/python.hpp>
#include <sstream>
#include <string>

using namespace boost::python;

bool has_letter(const char * text, const char letter) {
    const char * ptr = text;
    while (char c = *(ptr++)) {
        if (c == letter) {
            return true;
        }
    }
    return false;
}

struct Native
{
    std::string name;
    long number;
    std::string pointer;

    Native(std::string name, long number, bool yes): name(name), number(number) {
        this->pointer = std::string(yes ? "YES" : "NO");
    }

    std::string summary() {
        std::stringstream ss;
        ss << "Native " << this->name << " number " << this->number << " pointer " << pointer;
        return ss.str();
    }
};

BOOST_PYTHON_MODULE(boost)
{
    def("has_letter", has_letter);

    class_<Native>("Native", init<std::string, long, bool>())
        .def_readwrite("name", &Native::name)
        .def_readwrite("number", &Native::number)
        .def_readonly("pointer", &Native::pointer)
        .def("summary", &Native::summary)
    ;

}
<commit_msg>correction<commit_after>#include <boost/python.hpp>
#include <sstream>
#include <string>

using namespace boost::python;

bool has_letter(const char * text, const char letter) {
    const char * ptr = text;
    while (char c = *(ptr++)) {
        if (c == letter) {
            return true;
        }
    }
    return false;
}

struct Native
{
    std::string name;
    long number;
    std::string pointer;

    Native(std::string name, long number, bool yes): name(name), number(number) {
        this->pointer = std::string(yes ? "YES" : "NO");
    }

    std::string summary() {
        std::stringstream ss;
        ss << "Native " << this->name << " number " << this->number << " pointer " << this->pointer;
        return ss.str();
    }
};

BOOST_PYTHON_MODULE(boost)
{
    def("has_letter", has_letter);

    class_<Native>("Native", init<std::string, long, bool>())
        .def_readwrite("name", &Native::name)
        .def_readwrite("number", &Native::number)
        .def_readonly("pointer", &Native::pointer)
        .def("summary", &Native::summary)
    ;

}
<|endoftext|>


<commit_before>// $Id: residue.C,v 1.5 1999/12/30 18:05:34 oliver Exp $

#include <BALL/KERNEL/residue.h>

#include <BALL/KERNEL/chain.h>
#include <BALL/KERNEL/protein.h>

using namespace std;

namespace BALL
{

	Residue::Residue()
		:	Fragment(),
			id_(BALL_RESIDUE_DEFAULT_ID),
			insertion_code_(BALL_RESIDUE_DEFAULT_INSERTION_CODE)
	{
	}

	Residue::Residue(const Residue& residue, bool deep)
		:	Fragment(residue, deep),
			id_(residue.id_),
			insertion_code_(residue.insertion_code_)
	{
	}

	Residue::Residue(const String& name, const String& id, char insertion_code)
		:	Fragment(name),
			id_(id),
			insertion_code_(insertion_code)
	{
	}

	Residue::~Residue()
	{
		destroy();
	}

	void Residue::clear()
	{
		Fragment::clear();

		clear_();
	}

	void Residue::destroy()
	{
		Fragment::destroy();

		clear_();
	}

	void Residue::persistentWrite(PersistenceManager& pm, const char* name) const
	{
		pm.writeObjectHeader(this, name);
			Fragment::persistentWrite(pm);
			pm.writePrimitive(id_, "id_");
			pm.writePrimitive(insertion_code_, "insertion_code_");
		pm.writeObjectTrailer(name);
	}

	void Residue::persistentRead(PersistenceManager& pm)
	{
		pm.checkObjectHeader(RTTI::getStreamName<Fragment>());
			Fragment::persistentRead(pm);
		pm.checkObjectTrailer(0);

		pm.readPrimitive(id_, "id_");
		pm.readPrimitive(insertion_code_, "insertion_code_");
	}

	void Residue::set(const Residue& residue, bool deep)
	{
		Fragment::set(residue, deep);

		id_ = residue.id_;
		insertion_code_ = residue.insertion_code_;
	}

	Residue& Residue::operator =(const Residue& residue)
	{
		set(residue);

		return *this;
	}

	void Residue::get(Residue& residue, bool deep) const
	{
		residue.set(*this, deep);
	}

	void Residue::swap(Residue& residue)
	{
		Fragment::swap(residue);

		id_.swap(residue.id_);

		char temp_insertion_code = insertion_code_;
		insertion_code_ = residue.insertion_code_;
		residue.insertion_code_ = temp_insertion_code;
	}

	Protein* Residue::getProtein()
	{
		for (Composite::AncestorIterator ancestor_it = beginAncestor(); !ancestor_it.isEnd(); ++ancestor_it)
		{
			if (RTTI::isKindOf<Protein>(*ancestor_it))
			{
				return (Protein *)&*ancestor_it;
			}
		}

		return 0;
	}

	const Protein *Residue::getProtein() const
	{
		return ((Residue *)this)->getProtein();
	}

	Chain* Residue::getChain()
	{
		for (Composite::AncestorIterator ancestor_it = beginAncestor(); !ancestor_it.isEnd(); ++ancestor_it)
		{
			if (RTTI::isKindOf<Chain>(*ancestor_it))
			{
				return (Chain *)&*ancestor_it;
			}
		}

		return 0;
	}

	const Chain *Residue::getChain() const
	{
		return ((Residue *)this)->getChain();
	}

	PDBAtom *Residue::getPDBAtom(Index index)
	{
		if (index < 0)
			throw Exception::IndexUnderflow(__FILE__, __LINE__, index);

		for (PDBAtomIterator protein_atom_iterator = beginPDBAtom();
				 !protein_atom_iterator.isEnd(); ++protein_atom_iterator)
		{
			if (index-- == 0)
			{
				return &(*protein_atom_iterator);
			}
		}

		return 0;
	}

	const PDBAtom* Residue::getPDBAtom(Index index) const
	{
		return ((Residue *)this)->getPDBAtom(index);
	}

	void Residue::setID(const String &id)
	{
		id_ = id;
	}

	String & Residue::getID()
	{
		return id_;
	}

	const String &Residue::getID() const
	{
		return id_;
	}

	void Residue::setInsertionCode(char insertion_code)
	{
		insertion_code_ = insertion_code;
	}

	char Residue::getInsertionCode() const
	{
		return insertion_code_;
	}

	Size Residue::countPDBAtoms() const
	{
		register Size size = 0;

		for (PDBAtomIterator protein_atom_iterator = beginPDBAtom();
				 !protein_atom_iterator.isEnd(); ++protein_atom_iterator)
		{
			++size;
		}

		return size;
	}

	void Residue::prepend(PDBAtom &protein_atom)
	{
		Fragment::prepend(protein_atom);
	}

	void Residue::append(PDBAtom& protein_atom)
	{
		Fragment::append(protein_atom);
	}

	void
	Residue::insert(PDBAtom& protein_atom)
	{
		Fragment::insert(protein_atom);
	}

	void Residue::insertBefore(PDBAtom& protein_atom, Composite& before)
	{
		Fragment::insertBefore(protein_atom, before);
	}

	void Residue::insertAfter(PDBAtom& protein_atom, Composite& after)
	{
		Fragment::insertAfter(protein_atom, after);
	}

	bool Residue::remove(PDBAtom& protein_atom)
	{
		return Fragment::remove(protein_atom);
	}

	void Residue::spliceBefore(Residue& residue)
	{
		Fragment::spliceBefore(residue);
	}

	void Residue::spliceAfter(Residue& residue)
	{
		Fragment::spliceAfter(residue);
	}

	void Residue::splice(Residue& residue)
	{
		Fragment::splice(residue);
	}

	bool Residue::isAminoAcid() const
	{
		return hasProperty(PROPERTY__AMINO_ACID);
	}

	bool Residue::isTerminal() const
	{
		return (isNTerminal() || isCTerminal());
	}

	bool Residue::isNTerminal() const
	{
		if (isAminoAcid() == true)
		{
			const Chain* chain = getChain();

			if (chain != 0)
			{
				ResidueConstIterator res_it = chain->beginResidue();
				for (; +res_it && &(*res_it) != this && !res_it->isAminoAcid(); ++res_it);

				return (&(*res_it) == this);
			}
		}

		return false;
	}

	bool Residue::isCTerminal() const
	{
		if (isAminoAcid() == true)
		{
			const Chain* chain = getChain();

			if (chain != 0)
			{
				ResidueConstIterator res_it = chain->rbeginResidue();
				for (; +res_it && &(*res_it) != this && !res_it->isAminoAcid(); --res_it);

				return (&(*res_it) == this);
			}
		}

		return false;
	}

	bool Residue::isValid() const
	{
		if (Fragment::isValid() == false
				|| id_.isValid() == false)
		{
			return false;
		}

		return true;
	}

	void Residue::dump(ostream& s, Size depth) const
	{
		BALL_DUMP_STREAM_PREFIX(s);

		Fragment::dump(s, depth);

		BALL_DUMP_DEPTH(s, depth);
		s << "  id: " << id_ << endl;

		BALL_DUMP_DEPTH(s, depth);
		s << "  insertion code: " << insertion_code_ << endl;

		BALL_DUMP_STREAM_SUFFIX(s);
	}

	void Residue::read(istream&  /* s */)
	{
		throw Exception::NotImplemented(__FILE__, __LINE__);
	}

	void Residue::write(ostream&  /*s */) const
	{
		throw Exception::NotImplemented(__FILE__, __LINE__);
	}

	void Residue::clear_()
	{
		id_ = BALL_RESIDUE_DEFAULT_ID;
		insertion_code_ = BALL_RESIDUE_DEFAULT_INSERTION_CODE;
	}

} // namespace BALL
<commit_msg>added: getFullName method<commit_after>// $Id: residue.C,v 1.6 2000/02/10 15:12:45 oliver Exp $

#include <BALL/KERNEL/residue.h>

#include <BALL/KERNEL/chain.h>
#include <BALL/KERNEL/protein.h>

using namespace std;

namespace BALL
{

	Residue::Residue()
		:	Fragment(),
			id_(BALL_RESIDUE_DEFAULT_ID),
			insertion_code_(BALL_RESIDUE_DEFAULT_INSERTION_CODE)
	{
	}

	Residue::Residue(const Residue& residue, bool deep)
		:	Fragment(residue, deep),
			id_(residue.id_),
			insertion_code_(residue.insertion_code_)
	{
	}

	Residue::Residue(const String& name, const String& id, char insertion_code)
		:	Fragment(name),
			id_(id),
			insertion_code_(insertion_code)
	{
	}

	Residue::~Residue()
	{
		destroy();
	}

	void Residue::clear()
	{
		Fragment::clear();

		clear_();
	}

	void Residue::destroy()
	{
		Fragment::destroy();

		clear_();
	}

	void Residue::persistentWrite(PersistenceManager& pm, const char* name) const
	{
		pm.writeObjectHeader(this, name);
			Fragment::persistentWrite(pm);
			pm.writePrimitive(id_, "id_");
			pm.writePrimitive(insertion_code_, "insertion_code_");
		pm.writeObjectTrailer(name);
	}

	void Residue::persistentRead(PersistenceManager& pm)
	{
		pm.checkObjectHeader(RTTI::getStreamName<Fragment>());
			Fragment::persistentRead(pm);
		pm.checkObjectTrailer(0);

		pm.readPrimitive(id_, "id_");
		pm.readPrimitive(insertion_code_, "insertion_code_");
	}

	void Residue::set(const Residue& residue, bool deep)
	{
		Fragment::set(residue, deep);

		id_ = residue.id_;
		insertion_code_ = residue.insertion_code_;
	}

	Residue& Residue::operator =(const Residue& residue)
	{
		set(residue);

		return *this;
	}

	void Residue::get(Residue& residue, bool deep) const
	{
		residue.set(*this, deep);
	}

	void Residue::swap(Residue& residue)
	{
		Fragment::swap(residue);

		id_.swap(residue.id_);

		char temp_insertion_code = insertion_code_;
		insertion_code_ = residue.insertion_code_;
		residue.insertion_code_ = temp_insertion_code;
	}

	Protein* Residue::getProtein()
	{
		for (Composite::AncestorIterator ancestor_it = beginAncestor(); !ancestor_it.isEnd(); ++ancestor_it)
		{
			if (RTTI::isKindOf<Protein>(*ancestor_it))
			{
				return (Protein *)&*ancestor_it;
			}
		}

		return 0;
	}

	const Protein *Residue::getProtein() const
	{
		return ((Residue *)this)->getProtein();
	}

	Chain* Residue::getChain()
	{
		for (Composite::AncestorIterator ancestor_it = beginAncestor(); !ancestor_it.isEnd(); ++ancestor_it)
		{
			if (RTTI::isKindOf<Chain>(*ancestor_it))
			{
				return (Chain *)&*ancestor_it;
			}
		}

		return 0;
	}

	const Chain *Residue::getChain() const
	{
		return ((Residue *)this)->getChain();
	}

	PDBAtom *Residue::getPDBAtom(Index index)
	{
		if (index < 0)
			throw Exception::IndexUnderflow(__FILE__, __LINE__, index);

		for (PDBAtomIterator protein_atom_iterator = beginPDBAtom();
				 !protein_atom_iterator.isEnd(); ++protein_atom_iterator)
		{
			if (index-- == 0)
			{
				return &(*protein_atom_iterator);
			}
		}

		return 0;
	}

	const PDBAtom* Residue::getPDBAtom(Index index) const
	{
		return ((Residue *)this)->getPDBAtom(index);
	}

	void Residue::setID(const String &id)
	{
		id_ = id;
	}

	String & Residue::getID()
	{
		return id_;
	}

	const String &Residue::getID() const
	{
		return id_;
	}

	void Residue::setInsertionCode(char insertion_code)
	{
		insertion_code_ = insertion_code;
	}

	char Residue::getInsertionCode() const
	{
		return insertion_code_;
	}

	Size Residue::countPDBAtoms() const
	{
		register Size size = 0;

		for (PDBAtomIterator protein_atom_iterator = beginPDBAtom();
				 !protein_atom_iterator.isEnd(); ++protein_atom_iterator)
		{
			++size;
		}

		return size;
	}

	void Residue::prepend(PDBAtom &protein_atom)
	{
		Fragment::prepend(protein_atom);
	}

	void Residue::append(PDBAtom& protein_atom)
	{
		Fragment::append(protein_atom);
	}

	void
	Residue::insert(PDBAtom& protein_atom)
	{
		Fragment::insert(protein_atom);
	}

	void Residue::insertBefore(PDBAtom& protein_atom, Composite& before)
	{
		Fragment::insertBefore(protein_atom, before);
	}

	void Residue::insertAfter(PDBAtom& protein_atom, Composite& after)
	{
		Fragment::insertAfter(protein_atom, after);
	}

	bool Residue::remove(PDBAtom& protein_atom)
	{
		return Fragment::remove(protein_atom);
	}

	void Residue::spliceBefore(Residue& residue)
	{
		Fragment::spliceBefore(residue);
	}

	void Residue::spliceAfter(Residue& residue)
	{
		Fragment::spliceAfter(residue);
	}

	void Residue::splice(Residue& residue)
	{
		Fragment::splice(residue);
	}

	bool Residue::isAminoAcid() const
	{
		return hasProperty(PROPERTY__AMINO_ACID);
	}

	bool Residue::isTerminal() const
	{
		return (isNTerminal() || isCTerminal());
	}

	bool Residue::isNTerminal() const
	{
		if (isAminoAcid() == true)
		{
			const Chain* chain = getChain();

			if (chain != 0)
			{
				ResidueConstIterator res_it = chain->beginResidue();
				for (; +res_it && &(*res_it) != this && !res_it->isAminoAcid(); ++res_it);

				return (&(*res_it) == this);
			}
		}

		return false;
	}

	bool Residue::isCTerminal() const
	{
		if (isAminoAcid() == true)
		{
			const Chain* chain = getChain();

			if (chain != 0)
			{
				ResidueConstIterator res_it = chain->rbeginResidue();
				for (; +res_it && &(*res_it) != this && !res_it->isAminoAcid(); --res_it);

				return (&(*res_it) == this);
			}
		}

		return false;
	}

	bool Residue::isValid() const
	{
		if (Fragment::isValid() == false
				|| id_.isValid() == false)
		{
			return false;
		}

		return true;
	}

	void Residue::dump(ostream& s, Size depth) const
	{
		BALL_DUMP_STREAM_PREFIX(s);

		Fragment::dump(s, depth);

		BALL_DUMP_DEPTH(s, depth);
		s << "  id: " << id_ << endl;

		BALL_DUMP_DEPTH(s, depth);
		s << "  insertion code: " << insertion_code_ << endl;

		BALL_DUMP_STREAM_SUFFIX(s);
	}

	void Residue::read(istream&  /* s */)
	{
		throw Exception::NotImplemented(__FILE__, __LINE__);
	}

	void Residue::write(ostream&  /*s */) const
	{
		throw Exception::NotImplemented(__FILE__, __LINE__);
	}

	void Residue::clear_()
	{
		id_ = BALL_RESIDUE_DEFAULT_ID;
		insertion_code_ = BALL_RESIDUE_DEFAULT_INSERTION_CODE;
	}

	String Residue::getFullName() const
	{
		String full_name = getName();
		full_name.trim();
		String suffix = "-";
		if (isNTerminal())
		{
			suffix = "-N";
		}
		if (isCTerminal())
		{
			suffix = "-C";
		}
		if (isCTerminal() && isNTerminal())
		{
			suffix = "-M";
		}
		if (hasProperty(Residue::PROPERTY__HAS_SSBOND))
		{
			suffix += "S";
		}

		if (suffix != "-")
		{
			full_name += suffix;
		}

		return full_name;
	}

} // namespace BALL
<|endoftext|>


<commit_before>//
// File:          edu_csdms_models_stm_SteadyStateAg_Impl.hxx
// Symbol:        edu.csdms.models.stm.SteadyStateAg-v0.0
// Symbol Type:   class
// Babel Version: 1.4.0 (Revision: 6607 release-1-4-0-branch)
// Description:   Server-side implementation for edu.csdms.models.stm.SteadyStateAg
//
// WARNING: Automatically generated; only changes within splicers preserved
//
//

#ifndef included_edu_csdms_models_stm_SteadyStateAg_Impl_hxx
#define included_edu_csdms_models_stm_SteadyStateAg_Impl_hxx

#ifndef included_sidl_cxx_hxx
#include "sidl_cxx.hxx"
#endif
#ifndef included_edu_csdms_models_stm_SteadyStateAg_IOR_h
#include "edu_csdms_models_stm_SteadyStateAg_IOR.h"
#endif
#ifndef included_edu_csdms_models_stm_SteadyStateAg_hxx
#include "edu_csdms_models_stm_SteadyStateAg.hxx"
#endif
#ifndef included_edu_csdms_openmi_IElementSet_hxx
#include "edu_csdms_openmi_IElementSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_IScalarSet_hxx
#include "edu_csdms_openmi_IScalarSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_IValueSet_hxx
#include "edu_csdms_openmi_IValueSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_ScalarSet_hxx
#include "edu_csdms_openmi_ScalarSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_ValueSet_hxx
#include "edu_csdms_openmi_ValueSet.hxx"
#endif
#ifndef included_edu_csdms_ports_IRFPort_hxx
#include "edu_csdms_ports_IRFPort.hxx"
#endif
#ifndef included_edu_csdms_tools_ConfigDialog_hxx
#include "edu_csdms_tools_ConfigDialog.hxx"
#endif
#ifndef included_edu_csdms_tools_TemplateFiles_hxx
#include "edu_csdms_tools_TemplateFiles.hxx"
#endif
#ifndef included_gov_cca_CCAException_hxx
#include "gov_cca_CCAException.hxx"
#endif
#ifndef included_gov_cca_Component_hxx
#include "gov_cca_Component.hxx"
#endif
#ifndef included_gov_cca_ComponentRelease_hxx
#include "gov_cca_ComponentRelease.hxx"
#endif
#ifndef included_gov_cca_Services_hxx
#include "gov_cca_Services.hxx"
#endif
#ifndef included_gov_cca_ports_ParameterPortFactory_hxx
#include "gov_cca_ports_ParameterPortFactory.hxx"
#endif
#ifndef included_sidl_BaseClass_hxx
#include "sidl_BaseClass.hxx"
#endif
#ifndef included_sidl_BaseInterface_hxx
#include "sidl_BaseInterface.hxx"
#endif
#ifndef included_sidl_ClassInfo_hxx
#include "sidl_ClassInfo.hxx"
#endif
#ifndef included_sidl_RuntimeException_hxx
#include "sidl_RuntimeException.hxx"
#endif

// DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._hincludes)
// Insert-Code-Here {edu.csdms.models.stm.SteadyStateAg._hincludes} (includes or arbitrary code)
#include "Initialize.h"
#include "Run.h"
#include "Finalize.h"
// DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._hincludes)

namespace edu {
  namespace csdms {
    namespace models {
      namespace stm {

        /**
         * Symbol "edu.csdms.models.stm.SteadyStateAg" (version 0.0)
         */
        class SteadyStateAg_impl : public virtual
          ::edu::csdms::models::stm::SteadyStateAg
        // DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._inherits)
        // Insert-Code-Here {edu.csdms.models.stm.SteadyStateAg._inherits} (optional inheritance here)
        // DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._inherits)

        {

        // All data marked protected will be accessable by
        // descendant Impl classes
        protected:

          bool _wrapped;

          // DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._implementation)

  // Insert-UserCode-Here(edu.csdms.models.stm.SteadyStateAg._implementation)
gov::cca::TypeMap userinput;

    int check, prints, k;
    double xhat[22], x[22], Qtbf[22], Sl[22], etahat[22], etadev[22], Bbf[22], Hbf[22];
    double Gt, L, ksidot, Qbf, B, D, Lamda, tauform;
    double aleh, lamdap, Cz, I, Cf, Omega, R, ksid, dt, Qt, C;
    double BMSS, Su, beta, time;

    double (*printmatrix)[22];

  // Bocca generated code. bocca.protected.begin(edu.csdms.models.stm.SteadyStateAg._implementation)

   gov::cca::Services    d_services; // our cca handle.

  // Bocca generated code. bocca.protected.end(edu.csdms.models.stm.SteadyStateAg._implementation)

          // DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._implementation)

        public:
          // default constructor, used for data wrapping(required)
          SteadyStateAg_impl();
          // sidl constructor (required)
          // Note: alternate Skel constructor doesn't call addref()
          // (fixes bug #275)
            SteadyStateAg_impl( struct
              edu_csdms_models_stm_SteadyStateAg__object * ior ) : StubBase(ior,
              true),
            ::gov::cca::Port((ior==NULL) ? NULL : &((*ior).d_gov_cca_port)),
            ::edu::csdms::ports::IRFPort((ior==NULL) ? NULL : &((
              *ior).d_edu_csdms_ports_irfport)),
            ::gov::cca::Component((ior==NULL) ? NULL : &((
              *ior).d_gov_cca_component)),
          ::gov::cca::ComponentRelease((ior==NULL) ? NULL : &((
            *ior).d_gov_cca_componentrelease)) , _wrapped(false) {_ctor();}

          // user defined construction
          void _ctor();

          // virtual destructor (required)
          virtual ~SteadyStateAg_impl() { _dtor(); }

          // user defined destruction
          void _dtor();

          // true if this object was created by a user newing the impl
          inline bool _isWrapped() {return _wrapped;}

          // static class initializer
          static void _load();

        public:

          /**
           * user defined non-static method.
           */
          void
          boccaSetServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           * user defined non-static method.
           */
          void
          boccaReleaseServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           *  This function should never be called, but helps babel generate better code.
           */
          void
          boccaForceUsePortInclude_impl (
            /* in */::gov::cca::ports::ParameterPortFactory& dummy0,
            /* in */::edu::csdms::openmi::ValueSet& dummy1,
            /* in */::edu::csdms::tools::TemplateFiles& dummy2,
            /* in */::edu::csdms::openmi::ScalarSet& dummy3,
            /* in */::edu::csdms::tools::ConfigDialog& dummy4,
            /* in */::edu::csdms::openmi::IScalarSet& dummy5
          )
          ;

          /**
           *  Starts up a component presence in the calling framework.
           * @param services the component instance's handle on the framework world.
           * Contracts concerning services and setServices:
           *
           * The component interaction with the CCA framework
           * and Ports begins on the call to setServices by the framework.
           *
           * This function is called exactly once for each instance created
           * by the framework.
           *
           * The argument services will never be nil/null.
           *
           * Those uses ports which are automatically connected by the framework
           * (so-called service-ports) may be obtained via getPort during
           * setServices.
           */
          void
          setServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           * Shuts down a component presence in the calling framework.
           * @param services the component instance's handle on the framework world.
           * Contracts concerning services and setServices:
           *
           * This function is called exactly once for each callback registered
           * through Services.
           *
           * The argument services will never be nil/null.
           * The argument services will always be the same as that received in
           * setServices.
           *
           * During this call the component should release any interfaces
           * acquired by getPort().
           *
           * During this call the component should reset to nil any stored
           * reference to services.
           *
           * After this call, the component instance will be removed from the
           * framework. If the component instance was created by the
           * framework, it will be destroyed, not recycled, The behavior of
           * any port references obtained from this component instance and
           * stored elsewhere becomes undefined.
           *
           * Notes for the component implementor:
           * 1) The component writer may perform blocking activities
           * within releaseServices, such as waiting for remote computations
           * to shutdown.
           * 2) It is good practice during releaseServices for the component
           * writer to remove or unregister all the ports it defined.
           */
          void
          releaseServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           * user defined non-static method.
           */
          void
          initialize_impl (
            /* in array<string> */::sidl::array< ::std::string>& properties
          )
          ;

          /**
           * user defined non-static method.
           */
          void
          run_impl (
            /* in */double time
          )
          ;

          /**
           * user defined non-static method.
           */
          void
          finalize_impl() ;
          /**
           * user defined non-static method.
           */
          int64_t
          getRaster_nx_impl() ;
          /**
           * user defined non-static method.
           */
          int64_t
          getRaster_ny_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_dx_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_dy_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_ulx_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_uly_impl() ;
          /**
           * user defined non-static method.
           */
          ::sidl::array<double>
          getRaster_grid_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::array<int32_t>
          get_raster_dimen_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::array<double>
          get_raster_res_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::basearray
          get_raster_data_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::array<double>
          get_time_span_impl() ;
          /**
           * user defined non-static method.
           */
          ::edu::csdms::openmi::IElementSet
          get_element_set_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::edu::csdms::openmi::IValueSet
          get_value_set_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::basearray
          get_value_set_data_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          void
          set_value_set_impl (
            /* in */const ::std::string& val_string,
            /* in */::edu::csdms::openmi::IValueSet& values
          )
          ;

        };  // end class SteadyStateAg_impl

      } // end namespace stm
    } // end namespace models
  } // end namespace csdms
} // end namespace edu

// DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._hmisc)
// Insert-Code-Here {edu.csdms.models.stm.SteadyStateAg._hmisc} (miscellaneous things)
// DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._hmisc)

#endif
<commit_msg>all models done with tab dialog<commit_after>//
// File:          edu_csdms_models_stm_SteadyStateAg_Impl.hxx
// Symbol:        edu.csdms.models.stm.SteadyStateAg-v0.0
// Symbol Type:   class
// Babel Version: 1.4.0 (Revision: 6607 release-1-4-0-branch)
// Description:   Server-side implementation for edu.csdms.models.stm.SteadyStateAg
//
// WARNING: Automatically generated; only changes within splicers preserved
//
//

#ifndef included_edu_csdms_models_stm_SteadyStateAg_Impl_hxx
#define included_edu_csdms_models_stm_SteadyStateAg_Impl_hxx

#ifndef included_sidl_cxx_hxx
#include "sidl_cxx.hxx"
#endif
#ifndef included_edu_csdms_models_stm_SteadyStateAg_IOR_h
#include "edu_csdms_models_stm_SteadyStateAg_IOR.h"
#endif
#ifndef included_edu_csdms_models_stm_SteadyStateAg_hxx
#include "edu_csdms_models_stm_SteadyStateAg.hxx"
#endif
#ifndef included_edu_csdms_openmi_IElementSet_hxx
#include "edu_csdms_openmi_IElementSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_IScalarSet_hxx
#include "edu_csdms_openmi_IScalarSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_IValueSet_hxx
#include "edu_csdms_openmi_IValueSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_ScalarSet_hxx
#include "edu_csdms_openmi_ScalarSet.hxx"
#endif
#ifndef included_edu_csdms_openmi_ValueSet_hxx
#include "edu_csdms_openmi_ValueSet.hxx"
#endif
#ifndef included_edu_csdms_ports_IRFPort_hxx
#include "edu_csdms_ports_IRFPort.hxx"
#endif
#ifndef included_edu_csdms_tools_ConfigDialog_hxx
#include "edu_csdms_tools_ConfigDialog.hxx"
#endif
#ifndef included_edu_csdms_tools_TemplateFiles_hxx
#include "edu_csdms_tools_TemplateFiles.hxx"
#endif
#ifndef included_gov_cca_CCAException_hxx
#include "gov_cca_CCAException.hxx"
#endif
#ifndef included_gov_cca_Component_hxx
#include "gov_cca_Component.hxx"
#endif
#ifndef included_gov_cca_ComponentRelease_hxx
#include "gov_cca_ComponentRelease.hxx"
#endif
#ifndef included_gov_cca_Services_hxx
#include "gov_cca_Services.hxx"
#endif
#ifndef included_gov_cca_ports_ParameterPortFactory_hxx
#include "gov_cca_ports_ParameterPortFactory.hxx"
#endif
#ifndef included_sidl_BaseClass_hxx
#include "sidl_BaseClass.hxx"
#endif
#ifndef included_sidl_BaseInterface_hxx
#include "sidl_BaseInterface.hxx"
#endif
#ifndef included_sidl_ClassInfo_hxx
#include "sidl_ClassInfo.hxx"
#endif
#ifndef included_sidl_RuntimeException_hxx
#include "sidl_RuntimeException.hxx"
#endif

// DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._hincludes)
// Insert-Code-Here {edu.csdms.models.stm.SteadyStateAg._hincludes} (includes or arbitrary code)
#include "Initialize.h"
#include "Run.h"
#include "Finalize.h"
// DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._hincludes)

namespace edu {
  namespace csdms {
    namespace models {
      namespace stm {

        /**
         * Symbol "edu.csdms.models.stm.SteadyStateAg" (version 0.0)
         */
        class SteadyStateAg_impl : public virtual
          ::edu::csdms::models::stm::SteadyStateAg
        // DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._inherits)
        // Insert-Code-Here {edu.csdms.models.stm.SteadyStateAg._inherits} (optional inheritance here)
        // DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._inherits)

        {

        // All data marked protected will be accessable by
        // descendant Impl classes
        protected:

          bool _wrapped;

          // DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._implementation)

  // Insert-UserCode-Here(edu.csdms.models.stm.SteadyStateAg._implementation)
gov::cca::TypeMap userinput;

    int check, prints, k;
    double xhat[22], x[22], Qtbf[22], Sl[22], etahat[22], etadev[22], Bbf[22], Hbf[22];
    double Gt, L, ksidot, Qbf, B, D, Lamda, tauform;
    double aleh, lamdap, Cz, I, Cf, Omega, R, ksid, dt, Qt, C;
    double BMSS, Su, beta, __time;

    double (*printmatrix)[22];

  // Bocca generated code. bocca.protected.begin(edu.csdms.models.stm.SteadyStateAg._implementation)

   gov::cca::Services    d_services; // our cca handle.

  // Bocca generated code. bocca.protected.end(edu.csdms.models.stm.SteadyStateAg._implementation)

          // DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._implementation)

        public:
          // default constructor, used for data wrapping(required)
          SteadyStateAg_impl();
          // sidl constructor (required)
          // Note: alternate Skel constructor doesn't call addref()
          // (fixes bug #275)
            SteadyStateAg_impl( struct
              edu_csdms_models_stm_SteadyStateAg__object * ior ) : StubBase(ior,
              true),
            ::gov::cca::Port((ior==NULL) ? NULL : &((*ior).d_gov_cca_port)),
            ::edu::csdms::ports::IRFPort((ior==NULL) ? NULL : &((
              *ior).d_edu_csdms_ports_irfport)),
            ::gov::cca::Component((ior==NULL) ? NULL : &((
              *ior).d_gov_cca_component)),
          ::gov::cca::ComponentRelease((ior==NULL) ? NULL : &((
            *ior).d_gov_cca_componentrelease)) , _wrapped(false) {_ctor();}

          // user defined construction
          void _ctor();

          // virtual destructor (required)
          virtual ~SteadyStateAg_impl() { _dtor(); }

          // user defined destruction
          void _dtor();

          // true if this object was created by a user newing the impl
          inline bool _isWrapped() {return _wrapped;}

          // static class initializer
          static void _load();

        public:

          /**
           * user defined non-static method.
           */
          void
          boccaSetServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           * user defined non-static method.
           */
          void
          boccaReleaseServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           *  This function should never be called, but helps babel generate better code.
           */
          void
          boccaForceUsePortInclude_impl (
            /* in */::gov::cca::ports::ParameterPortFactory& dummy0,
            /* in */::edu::csdms::openmi::ValueSet& dummy1,
            /* in */::edu::csdms::tools::TemplateFiles& dummy2,
            /* in */::edu::csdms::openmi::ScalarSet& dummy3,
            /* in */::edu::csdms::tools::ConfigDialog& dummy4,
            /* in */::edu::csdms::openmi::IScalarSet& dummy5
          )
          ;

          /**
           *  Starts up a component presence in the calling framework.
           * @param services the component instance's handle on the framework world.
           * Contracts concerning services and setServices:
           *
           * The component interaction with the CCA framework
           * and Ports begins on the call to setServices by the framework.
           *
           * This function is called exactly once for each instance created
           * by the framework.
           *
           * The argument services will never be nil/null.
           *
           * Those uses ports which are automatically connected by the framework
           * (so-called service-ports) may be obtained via getPort during
           * setServices.
           */
          void
          setServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           * Shuts down a component presence in the calling framework.
           * @param services the component instance's handle on the framework world.
           * Contracts concerning services and setServices:
           *
           * This function is called exactly once for each callback registered
           * through Services.
           *
           * The argument services will never be nil/null.
           * The argument services will always be the same as that received in
           * setServices.
           *
           * During this call the component should release any interfaces
           * acquired by getPort().
           *
           * During this call the component should reset to nil any stored
           * reference to services.
           *
           * After this call, the component instance will be removed from the
           * framework. If the component instance was created by the
           * framework, it will be destroyed, not recycled, The behavior of
           * any port references obtained from this component instance and
           * stored elsewhere becomes undefined.
           *
           * Notes for the component implementor:
           * 1) The component writer may perform blocking activities
           * within releaseServices, such as waiting for remote computations
           * to shutdown.
           * 2) It is good practice during releaseServices for the component
           * writer to remove or unregister all the ports it defined.
           */
          void
          releaseServices_impl (
            /* in */::gov::cca::Services& services
          )
          // throws:
          //    ::gov::cca::CCAException
          //    ::sidl::RuntimeException
          ;

          /**
           * user defined non-static method.
           */
          void
          initialize_impl (
            /* in array<string> */::sidl::array< ::std::string>& properties
          )
          ;

          /**
           * user defined non-static method.
           */
          void
          run_impl (
            /* in */double time
          )
          ;

          /**
           * user defined non-static method.
           */
          void
          finalize_impl() ;
          /**
           * user defined non-static method.
           */
          int64_t
          getRaster_nx_impl() ;
          /**
           * user defined non-static method.
           */
          int64_t
          getRaster_ny_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_dx_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_dy_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_ulx_impl() ;
          /**
           * user defined non-static method.
           */
          double
          getRaster_uly_impl() ;
          /**
           * user defined non-static method.
           */
          ::sidl::array<double>
          getRaster_grid_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::array<int32_t>
          get_raster_dimen_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::array<double>
          get_raster_res_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::basearray
          get_raster_data_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::array<double>
          get_time_span_impl() ;
          /**
           * user defined non-static method.
           */
          ::edu::csdms::openmi::IElementSet
          get_element_set_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::edu::csdms::openmi::IValueSet
          get_value_set_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          ::sidl::basearray
          get_value_set_data_impl (
            /* in */const ::std::string& val_string
          )
          ;

          /**
           * user defined non-static method.
           */
          void
          set_value_set_impl (
            /* in */const ::std::string& val_string,
            /* in */::edu::csdms::openmi::IValueSet& values
          )
          ;

        };  // end class SteadyStateAg_impl

      } // end namespace stm
    } // end namespace models
  } // end namespace csdms
} // end namespace edu

// DO-NOT-DELETE splicer.begin(edu.csdms.models.stm.SteadyStateAg._hmisc)
// Insert-Code-Here {edu.csdms.models.stm.SteadyStateAg._hmisc} (miscellaneous things)
// DO-NOT-DELETE splicer.end(edu.csdms.models.stm.SteadyStateAg._hmisc)

#endif
<|endoftext|>


<commit_before>#ifndef __BTREE_ITERATION_HPP__
#define __BTREE_ITERATION_HPP__

#include "errors.hpp"
#include <boost/shared_array.hpp>
#include <boost/shared_ptr.hpp>

#include "containers/iterators.hpp"
#include "btree/internal_node.hpp"
#include "btree/leaf_node.hpp"
#include "buffer_cache/buf_lock.hpp"
#include "btree/slice.hpp"
#include "memcached/store.hpp"

template <class Value>
struct key_value_pair_t {
    std::string key;
    boost::shared_array<char> value;

    key_value_pair_t(value_sizer_t<Value> *sizer, const std::string& _key, const Value *_value) : key(_key) {
        int size = sizer->size(reinterpret_cast<const Value *>(_value));
        value.reset(new char[size]);
        memcpy(value.get(), _value, size);
    }
};

/* leaf_iterator_t returns the keys of a btree leaf node one by one.
 * When it's done, it releases (deletes) the buf_lock object.
 *
 * TODO: should the buf_lock be released by the caller instead?
 */
template <class Value>
struct leaf_iterator_t : public one_way_iterator_t<key_value_pair_t<Value> > {
    leaf_iterator_t(const leaf_node_t *leaf, int index, buf_lock_t *lock, const boost::shared_ptr<value_sizer_t<Value> >& sizer, const boost::shared_ptr<transaction_t>& transaction);

    boost::optional<key_value_pair_t<Value> > next();
    void prefetch();
    virtual ~leaf_iterator_t();
private:
    void done();
    key_with_data_provider_t pair_to_key_with_data_provider(const btree_leaf_pair<Value>* pair);

    const leaf_node_t *leaf;
    int index;
    buf_lock_t *lock;
    boost::shared_ptr<value_sizer_t<Value> > sizer;
    boost::shared_ptr<transaction_t> transaction;
};

/* slice_leaves_iterator_t finds the first leaf that contains the given key (or
 * the next key, if left_open is true). It returns that leaf iterator (which
 * also contains the lock), however it doesn't release the leaf lock itself
 * (it's done by the leaf iterator).
 *
 * slice_leaves_iterator_t maintains internal state by locking some internal
 * nodes and unlocking them as iteration progresses. Currently this locking is
 * done in DFS manner, as described in the btree/rget.cc file comment.
 */
template <class Value>
class slice_leaves_iterator_t : public one_way_iterator_t<leaf_iterator_t<Value>*> {
    struct internal_node_state {
        internal_node_state(const internal_node_t *node, int index, buf_lock_t *lock)
            : node(node), index(index), lock(lock) { }

        const internal_node_t *node;
        int index;
        buf_lock_t *lock;
    };
public:
    slice_leaves_iterator_t(const boost::shared_ptr<value_sizer_t<Value> >& sizer, const boost::shared_ptr<transaction_t>& transaction, btree_slice_t *slice, rget_bound_mode_t left_mode, const btree_key_t *left_key, rget_bound_mode_t right_mode, const btree_key_t *right_key);

    boost::optional<leaf_iterator_t<Value>*> next();
    void prefetch();
    virtual ~slice_leaves_iterator_t();
private:
    void done();

    boost::optional<leaf_iterator_t<Value>*> get_first_leaf();
    boost::optional<leaf_iterator_t<Value>*> get_next_leaf();
    boost::optional<leaf_iterator_t<Value>*> get_leftmost_leaf(block_id_t node_id);
    block_id_t get_child_id(const internal_node_t *i_node, int index) const;

    boost::shared_ptr<value_sizer_t<Value> > sizer;
    boost::shared_ptr<transaction_t> transaction;
    btree_slice_t *slice;
    rget_bound_mode_t left_mode;
    const btree_key_t *left_key;
    rget_bound_mode_t right_mode;
    const btree_key_t *right_key;

    std::list<internal_node_state> traversal_state;
    bool started;
    bool nevermore;
};

/* slice_keys_iterator_t combines slice_leaves_iterator_t and leaf_iterator_t to allow you
 * to iterate through the keys of a particular slice in order.
 *
 * Use merge_ordered_data_iterator_t class to funnel multiple slice_keys_iterator_t instances,
 * e.g. to get a range query for all the slices.
 */
template <class Value>
class slice_keys_iterator_t : public one_way_iterator_t<key_value_pair_t<Value> > {
public:
    /* Cannot assume that 'start' and 'end' will remain valid after the constructor returns! */
    slice_keys_iterator_t(const boost::shared_ptr<value_sizer_t<Value> >& sizer, const boost::shared_ptr<transaction_t>& transaction, btree_slice_t *slice, rget_bound_mode_t left_mode, const store_key_t &left_key, rget_bound_mode_t right_mode, const store_key_t &right_key);
    virtual ~slice_keys_iterator_t();

    boost::optional<key_value_pair_t<Value> > next();
    void prefetch();
private:
    boost::optional<key_value_pair_t<Value> > get_first_value();
    boost::optional<key_value_pair_t<Value> > get_next_value();

    boost::optional<key_value_pair_t<Value> > validate_return_value(key_value_pair_t<Value> &pair) const;

    void done();

    boost::shared_ptr<value_sizer_t<Value> > sizer;
    boost::shared_ptr<transaction_t> transaction;
    btree_slice_t *slice;
    rget_bound_mode_t left_mode;
    btree_key_buffer_t left_key;
    rget_bound_mode_t right_mode;
    btree_key_buffer_t right_key;
    std::string left_str;
    std::string right_str;

    bool no_more_data;
    leaf_iterator_t<Value> *active_leaf;
    slice_leaves_iterator_t<Value> *leaves_iterator;
};

#include "btree/iteration.tcc"

#endif // __BTREE_ITERATION_HPP__
<commit_msg>Got things building in release mode with MOCK_CACHE_CHECK=1.<commit_after>#ifndef __BTREE_ITERATION_HPP__
#define __BTREE_ITERATION_HPP__

#include <list>

#include "errors.hpp"
#include <boost/shared_array.hpp>
#include <boost/shared_ptr.hpp>

#include "containers/iterators.hpp"
#include "btree/internal_node.hpp"
#include "btree/leaf_node.hpp"
#include "buffer_cache/buf_lock.hpp"
#include "btree/slice.hpp"
#include "memcached/store.hpp"

template <class Value>
struct key_value_pair_t {
    std::string key;
    boost::shared_array<char> value;

    key_value_pair_t(value_sizer_t<Value> *sizer, const std::string& _key, const Value *_value) : key(_key) {
        int size = sizer->size(reinterpret_cast<const Value *>(_value));
        value.reset(new char[size]);
        memcpy(value.get(), _value, size);
    }
};

/* leaf_iterator_t returns the keys of a btree leaf node one by one.
 * When it's done, it releases (deletes) the buf_lock object.
 *
 * TODO: should the buf_lock be released by the caller instead?
 */
template <class Value>
struct leaf_iterator_t : public one_way_iterator_t<key_value_pair_t<Value> > {
    leaf_iterator_t(const leaf_node_t *leaf, int index, buf_lock_t *lock, const boost::shared_ptr<value_sizer_t<Value> >& sizer, const boost::shared_ptr<transaction_t>& transaction);

    boost::optional<key_value_pair_t<Value> > next();
    void prefetch();
    virtual ~leaf_iterator_t();
private:
    void done();
    key_with_data_provider_t pair_to_key_with_data_provider(const btree_leaf_pair<Value>* pair);

    const leaf_node_t *leaf;
    int index;
    buf_lock_t *lock;
    boost::shared_ptr<value_sizer_t<Value> > sizer;
    boost::shared_ptr<transaction_t> transaction;
};

/* slice_leaves_iterator_t finds the first leaf that contains the given key (or
 * the next key, if left_open is true). It returns that leaf iterator (which
 * also contains the lock), however it doesn't release the leaf lock itself
 * (it's done by the leaf iterator).
 *
 * slice_leaves_iterator_t maintains internal state by locking some internal
 * nodes and unlocking them as iteration progresses. Currently this locking is
 * done in DFS manner, as described in the btree/rget.cc file comment.
 */
template <class Value>
class slice_leaves_iterator_t : public one_way_iterator_t<leaf_iterator_t<Value>*> {
    struct internal_node_state {
        internal_node_state(const internal_node_t *node, int index, buf_lock_t *lock)
            : node(node), index(index), lock(lock) { }

        const internal_node_t *node;
        int index;
        buf_lock_t *lock;
    };
public:
    slice_leaves_iterator_t(const boost::shared_ptr<value_sizer_t<Value> >& sizer, const boost::shared_ptr<transaction_t>& transaction, btree_slice_t *slice, rget_bound_mode_t left_mode, const btree_key_t *left_key, rget_bound_mode_t right_mode, const btree_key_t *right_key);

    boost::optional<leaf_iterator_t<Value>*> next();
    void prefetch();
    virtual ~slice_leaves_iterator_t();
private:
    void done();

    boost::optional<leaf_iterator_t<Value>*> get_first_leaf();
    boost::optional<leaf_iterator_t<Value>*> get_next_leaf();
    boost::optional<leaf_iterator_t<Value>*> get_leftmost_leaf(block_id_t node_id);
    block_id_t get_child_id(const internal_node_t *i_node, int index) const;

    boost::shared_ptr<value_sizer_t<Value> > sizer;
    boost::shared_ptr<transaction_t> transaction;
    btree_slice_t *slice;
    rget_bound_mode_t left_mode;
    const btree_key_t *left_key;
    rget_bound_mode_t right_mode;
    const btree_key_t *right_key;

    std::list<internal_node_state> traversal_state;
    bool started;
    bool nevermore;
};

/* slice_keys_iterator_t combines slice_leaves_iterator_t and leaf_iterator_t to allow you
 * to iterate through the keys of a particular slice in order.
 *
 * Use merge_ordered_data_iterator_t class to funnel multiple slice_keys_iterator_t instances,
 * e.g. to get a range query for all the slices.
 */
template <class Value>
class slice_keys_iterator_t : public one_way_iterator_t<key_value_pair_t<Value> > {
public:
    /* Cannot assume that 'start' and 'end' will remain valid after the constructor returns! */
    slice_keys_iterator_t(const boost::shared_ptr<value_sizer_t<Value> >& sizer, const boost::shared_ptr<transaction_t>& transaction, btree_slice_t *slice, rget_bound_mode_t left_mode, const store_key_t &left_key, rget_bound_mode_t right_mode, const store_key_t &right_key);
    virtual ~slice_keys_iterator_t();

    boost::optional<key_value_pair_t<Value> > next();
    void prefetch();
private:
    boost::optional<key_value_pair_t<Value> > get_first_value();
    boost::optional<key_value_pair_t<Value> > get_next_value();

    boost::optional<key_value_pair_t<Value> > validate_return_value(key_value_pair_t<Value> &pair) const;

    void done();

    boost::shared_ptr<value_sizer_t<Value> > sizer;
    boost::shared_ptr<transaction_t> transaction;
    btree_slice_t *slice;
    rget_bound_mode_t left_mode;
    btree_key_buffer_t left_key;
    rget_bound_mode_t right_mode;
    btree_key_buffer_t right_key;
    std::string left_str;
    std::string right_str;

    bool no_more_data;
    leaf_iterator_t<Value> *active_leaf;
    slice_leaves_iterator_t<Value> *leaves_iterator;
};

#include "btree/iteration.tcc"

#endif // __BTREE_ITERATION_HPP__
<|endoftext|>