<commit_before>//----------------------------------------------------------------------------
/// \file   running_stat.hpp
/// \author Serge Aleynikov
//----------------------------------------------------------------------------
/// This file implements a class that calculates running mean and
/// standard deviation.
//----------------------------------------------------------------------------
// Created: 2010-05-20
//----------------------------------------------------------------------------
/*
***** BEGIN LICENSE BLOCK *****

This file is part of the utxx open-source project

Copyright (C) 2010 Serge Aleynikov <saleyn@gmail.com>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

***** END LICENSE BLOCK *****
*/

#pragma once

#include <stdlib.h>
#include <math.h>
#include <limits>
#include <algorithm>
#include <stdexcept>
#include <assert.h>
#include <utxx/detail/running_stat_impl.hpp>
#include <utxx/compiler_hints.hpp>

namespace utxx {

//-----------------------------------------------------------------------------
/// Keep running min/max/average/variance stats.
//-----------------------------------------------------------------------------

/// Running count / sum / min / max statistics
template <typename T, typename CntType = size_t>
class basic_running_sum {
protected:
    CntType m_count;
    T       m_last, m_sum, m_min, m_max;
public:
    basic_running_sum() {
        clear();
    }

    basic_running_sum(const basic_running_sum& rhs)
        : m_count(rhs.m_count)
        , m_last(rhs.m_last), m_sum(rhs.m_sum)
        , m_min(rhs.m_min),   m_max(rhs.m_max)
    {}

#if __cplusplus >= 201103L
    basic_running_sum(basic_running_sum&& rhs)
        : m_count(rhs.m_count)
        , m_last(rhs.m_last), m_sum(rhs.m_sum)
        , m_min(rhs.m_min),   m_max(rhs.m_max)
    {}

    basic_running_sum<T, CntType>&
    operator=(basic_running_sum&& a_rhs) {
        m_count = a_rhs.m_count;
        m_last  = a_rhs.m_last;
        m_sum   = a_rhs.m_sum;
        m_min   = a_rhs.m_min;
        m_max   = a_rhs.m_max;
        return *this;
    }
#endif

    /// Reset the internal state.
    void clear() {
        m_count = 0; m_last = 0; m_sum = 0;
        m_min = std::numeric_limits<T>::max();
        m_max = std::numeric_limits<T>::lowest();
    }

    /// Add a sample measurement.
    inline void add(double x) {
        ++m_count;
        m_last = x;
        m_sum += x;
        if (x > m_max) m_max = x;
        if (x < m_min) m_min = x;
    }

    void operator+= (const basic_running_sum<T, CntType>& a) {
        m_count += a.m_count;
        m_sum   += a.m_sum;
        if (a.m_max > m_max) m_max = a.m_max;
        if (a.m_min < m_min) m_min = a.m_min;
    }

    void operator-= (const basic_running_sum<T, CntType>& a) {
        m_count -= a.count();
        m_sum   -= a.sum();
        //m_min    = a.min();
        //m_max    = a.max();
    }

    /// Number of samples since last invocation of clear().
    CntType     count() const { return m_count;  }
    bool        empty() const { return !m_count; }

    T           last()  const { return m_last; }
    T           sum()   const { return m_sum;  }
    double      mean()  const { return likely(m_count) ? double(m_sum) / m_count : 0.0; }
    T           min()   const { return m_min == std::numeric_limits<T>::max()
                                     ? 0 : m_min; }
    T           max()   const { return m_max == std::numeric_limits<T>::lowest()
                                     ? 0 : m_max; }
};

/// Running variance statistics
template <typename T, typename CntType = size_t>
class basic_running_variance : public basic_running_sum<T, CntType> {
    typedef basic_running_sum<T, CntType> base;
    double  m_var;
public:
    basic_running_variance() {
        clear();
    }

    basic_running_variance(const basic_running_variance& rhs)
        : base(rhs)
        , m_var(rhs.m_var)
    {}

    /// Reset the internal state.
    void clear() {
        base::clear();
        m_var = 0.0;
    }

    /// Add a sample measurement.
    inline void add(T x) {
        double old = this->mean();
        base::add(x);
        // See Knuth TAOCP v.2, 3rd ed, p.232
        double diff = x - old;
        if (diff != 0.0)
            m_var += diff * (x - base::mean());
    }

    /// Number of samples since last invocation of clear().
    double   variance()  const { return likely(this->m_count) ? m_var/this->m_count : 0.0; }
    double   deviation() const { return sqrt(variance()); }
};

template <typename T, int N = 0, bool FastMinMax = false>
struct basic_moving_average
    : public detail::minmax_impl<basic_moving_average<T,N,FastMinMax>, T, FastMinMax>
{
    typedef
        detail::minmax_impl<basic_moving_average<T,N,FastMinMax>, T, FastMinMax>
        base;

    friend base;

    explicit basic_moving_average(size_t a_capacity = 0)
        : MASK(N ? N-1 : a_capacity-1)
        , m_data(m_samples)
    {
        #if __cplusplus >= 201103L
        static_assert(!N || (N & (N-1)) == 0, "N must be 0 or power of 2");
        #else
        assert(!N || (N & (N-1)) == 0);
        #endif
        if (!(N ^ a_capacity))
            throw std::logic_error
                ("utxx::basic_moving_average: both static and dynamic capacity is given");
        if (a_capacity) {
            if ((a_capacity & (a_capacity-1)) != 0)
                throw std::invalid_argument
                    ("utxx::basic_moving_average: dynamic capacity must be power of 2");
            m_data = new T[a_capacity];
        }

        clear();
    }

    basic_moving_average(const basic_moving_average& a_rhs)
        : base(a_rhs)
        , MASK  (a_rhs.MASK)
        , m_end (a_rhs.m_end)
        , m_last(a_rhs.m_last)
        , m_sum (a_rhs.m_sum)
    {
        if (a_rhs.m_data == a_rhs.m_samples)
            m_data = m_samples;
        else {
            assert(N == 0);
            m_data = new T[capacity()];
        }

        memcpy(m_data, a_rhs.m_data, sizeof(T)*capacity());
    }

    #if __cplusplus >= 201103L
    basic_moving_average(basic_moving_average&& a_rhs)
        : base(a_rhs)
        , MASK  (a_rhs.MASK)
        , m_end (a_rhs.m_end)
        , m_last(a_rhs.m_last)
        , m_sum (a_rhs.m_sum)
    {
        if (a_rhs.m_data != a_rhs.m_samples) {
            assert(N == 0);
            m_data = a_rhs.m_data;
        } else {
            m_data = m_samples;
            memcpy(m_samples, a_rhs.m_samples, sizeof(T)*capacity());
        }
        // Reset the data pointer so that it's not
        a_rhs.m_data = nullptr;
        a_rhs.m_sum  = 0;
        a_rhs.m_last = 0;
        a_rhs.m_end  = 0;
    }
    #endif

    ~basic_moving_average() {
        if (m_data != m_samples)
            delete [] m_data;
    }

    void add(T sample) {
        m_last    = sample;
        T& oldest = m_data[m_end & MASK];
        m_sum    += sample;

        if (m_end > MASK)
           m_sum -= oldest;

        this->update_minmax(sample);

        oldest = sample;

        ++m_end;
    }

    void clear() {
        base::clear();
        if (m_data)
            memset(m_data, 0, capacity()*sizeof(T));
        m_sum  = 0;
        m_last = 0;
        m_end  = 0;
    }

    bool     empty()    const { return m_end == 0; }
    /// Capacity of the window
    size_t   capacity() const { return MASK+1; }
    /// Number of windowed items (<= capacity())
    size_t   size()     const { return m_end > MASK  ? capacity() : m_end; }
    /// Total number of samples processed since initialization
    size_t   total()    const { return m_end; }

    /// Access to raw samples
    const T* samples()  const { return m_data; }

    double   mean()     const { return likely(m_end) ? double(m_sum) / size() : 0.0; }
    T        sum()      const { return m_sum;  }
    T        last()     const { return m_last; }

    std::pair<T,T> minmax() const {
        if (unlikely(empty()))
            return std::make_pair
                (std::numeric_limits<T>::max(), std::numeric_limits<T>::min());
        return base::minmax();
    }

    T min() const { return base::min(); }
    T max() const { return base::max(); }

protected:
    template <typename D, typename U, bool F> friend class detail::minmax_impl;

    size_t  begin_idx()        const { return m_end - size(); }
    size_t  end_idx()          const { return m_end;          }
    T       data(size_t a_idx) const { return m_data[a_idx & MASK]; }

    const size_t    MASK;
    size_t          m_end;
    T               m_last;
    T               m_sum;
    T*              m_data;
    T               m_samples[N];
};

/**
 * Calculate a running weighted average of values on a given
 * windowing interval using exponential decay.
 */
class weighted_average {
    size_t m_sec_interval;  ///< Number of seconds in the averaging window
    size_t m_last_seconds;  ///< Last reported timeval.tv_sec.
    double m_last;          ///< Last reported value.

    double m_last_wavg;     ///< Last weighted average
    double m_denominator;   ///< Equals m_sec_interval*60

    void reset(size_t a_sec_interval) {
        interval(a_sec_interval);
        m_last_seconds = 0;
        m_last = m_last_wavg = 0;
    }

public:
    explicit weighted_average(size_t a_sec_interval = 15u) {
        reset(a_sec_interval);
    }

    /// Obtain weighted exponential average
    double calculate(size_t a_now_sec, double a_value) {
        return calculate_exp(a_now_sec, a_value);
    }

    /// Obtain exponential moving average
    double calculate_ema(size_t a_now_sec, double a_value) {
      auto fun = [=]() { return 2.0/(1.0+interval()); };
      return calculate(a_now_sec, a_value, fun);
    }

    /// Obtain weighted exponential average
    double calculate_exp(size_t a_now_sec, double a_value) {
      auto fun = [=]() { return exp(-(double)(a_now_sec - m_last_seconds) / m_denominator); };
      return calculate(a_now_sec, a_value, fun);
    }

    template <typename AlphaFun>
    double calculate(size_t a_now_sec, double a_value, AlphaFun fun) {
      double alpha    = AlphaFun();
      m_last_wavg     = a_value + alpha * (m_last_wavg - a_value);
      m_last          = a_value;
      m_last_seconds  = a_now_sec;
      return m_last_wavg;
    }

    /// Clear internal state
    void clear() { reset(m_sec_interval); }

    double last_value()     const { return m_last;      }
    double last_weighted()  const { return m_last_wavg; }

    /// Get windowing interval in seconds
    size_t interval()       const { return m_sec_interval; }

    /// Set windowing interval in seconds
    void interval(size_t a_sec_interval) {
        if (a_sec_interval == 0)
            throw std::out_of_range("Argument must be > 0!");
        m_sec_interval = a_sec_interval;
        m_denominator  = a_sec_interval * 60;
    }
};

} // namespace utxx
<commit_msg>Fix compilation issue<commit_after>//----------------------------------------------------------------------------
/// \file   running_stat.hpp
/// \author Serge Aleynikov
//----------------------------------------------------------------------------
/// This file implements a class that calculates running mean and
/// standard deviation.
//----------------------------------------------------------------------------
// Created: 2010-05-20
//----------------------------------------------------------------------------
/*
***** BEGIN LICENSE BLOCK *****

This file is part of the utxx open-source project

Copyright (C) 2010 Serge Aleynikov <saleyn@gmail.com>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

***** END LICENSE BLOCK *****
*/

#pragma once

#include <stdlib.h>
#include <math.h>
#include <limits>
#include <algorithm>
#include <stdexcept>
#include <assert.h>
#include <utxx/detail/running_stat_impl.hpp>
#include <utxx/compiler_hints.hpp>

namespace utxx {

//-----------------------------------------------------------------------------
/// Keep running min/max/average/variance stats.
//-----------------------------------------------------------------------------

/// Running count / sum / min / max statistics
template <typename T, typename CntType = size_t>
class basic_running_sum {
protected:
    CntType m_count;
    T       m_last, m_sum, m_min, m_max;
public:
    basic_running_sum() {
        clear();
    }

    basic_running_sum(const basic_running_sum& rhs)
        : m_count(rhs.m_count)
        , m_last(rhs.m_last), m_sum(rhs.m_sum)
        , m_min(rhs.m_min),   m_max(rhs.m_max)
    {}

#if __cplusplus >= 201103L
    basic_running_sum(basic_running_sum&& rhs)
        : m_count(rhs.m_count)
        , m_last(rhs.m_last), m_sum(rhs.m_sum)
        , m_min(rhs.m_min),   m_max(rhs.m_max)
    {}

    basic_running_sum<T, CntType>&
    operator=(basic_running_sum&& a_rhs) {
        m_count = a_rhs.m_count;
        m_last  = a_rhs.m_last;
        m_sum   = a_rhs.m_sum;
        m_min   = a_rhs.m_min;
        m_max   = a_rhs.m_max;
        return *this;
    }
#endif

    /// Reset the internal state.
    void clear() {
        m_count = 0; m_last = 0; m_sum = 0;
        m_min = std::numeric_limits<T>::max();
        m_max = std::numeric_limits<T>::lowest();
    }

    /// Add a sample measurement.
    inline void add(double x) {
        ++m_count;
        m_last = x;
        m_sum += x;
        if (x > m_max) m_max = x;
        if (x < m_min) m_min = x;
    }

    void operator+= (const basic_running_sum<T, CntType>& a) {
        m_count += a.m_count;
        m_sum   += a.m_sum;
        if (a.m_max > m_max) m_max = a.m_max;
        if (a.m_min < m_min) m_min = a.m_min;
    }

    void operator-= (const basic_running_sum<T, CntType>& a) {
        m_count -= a.count();
        m_sum   -= a.sum();
        //m_min    = a.min();
        //m_max    = a.max();
    }

    /// Number of samples since last invocation of clear().
    CntType     count() const { return m_count;  }
    bool        empty() const { return !m_count; }

    T           last()  const { return m_last; }
    T           sum()   const { return m_sum;  }
    double      mean()  const { return likely(m_count) ? double(m_sum) / m_count : 0.0; }
    T           min()   const { return m_min == std::numeric_limits<T>::max()
                                     ? 0 : m_min; }
    T           max()   const { return m_max == std::numeric_limits<T>::lowest()
                                     ? 0 : m_max; }
};

/// Running variance statistics
template <typename T, typename CntType = size_t>
class basic_running_variance : public basic_running_sum<T, CntType> {
    typedef basic_running_sum<T, CntType> base;
    double  m_var;
public:
    basic_running_variance() {
        clear();
    }

    basic_running_variance(const basic_running_variance& rhs)
        : base(rhs)
        , m_var(rhs.m_var)
    {}

    /// Reset the internal state.
    void clear() {
        base::clear();
        m_var = 0.0;
    }

    /// Add a sample measurement.
    inline void add(T x) {
        double old = this->mean();
        base::add(x);
        // See Knuth TAOCP v.2, 3rd ed, p.232
        double diff = x - old;
        if (diff != 0.0)
            m_var += diff * (x - base::mean());
    }

    /// Number of samples since last invocation of clear().
    double   variance()  const { return likely(this->m_count) ? m_var/this->m_count : 0.0; }
    double   deviation() const { return sqrt(variance()); }
};

template <typename T, int N = 0, bool FastMinMax = false>
struct basic_moving_average
    : public detail::minmax_impl<basic_moving_average<T,N,FastMinMax>, T, FastMinMax>
{
    typedef
        detail::minmax_impl<basic_moving_average<T,N,FastMinMax>, T, FastMinMax>
        base;

    friend base;

    explicit basic_moving_average(size_t a_capacity = 0)
        : MASK(N ? N-1 : a_capacity-1)
        , m_data(m_samples)
    {
        #if __cplusplus >= 201103L
        static_assert(!N || (N & (N-1)) == 0, "N must be 0 or power of 2");
        #else
        assert(!N || (N & (N-1)) == 0);
        #endif
        if (!(N ^ a_capacity))
            throw std::logic_error
                ("utxx::basic_moving_average: both static and dynamic capacity is given");
        if (a_capacity) {
            if ((a_capacity & (a_capacity-1)) != 0)
                throw std::invalid_argument
                    ("utxx::basic_moving_average: dynamic capacity must be power of 2");
            m_data = new T[a_capacity];
        }

        clear();
    }

    basic_moving_average(const basic_moving_average& a_rhs)
        : base(a_rhs)
        , MASK  (a_rhs.MASK)
        , m_end (a_rhs.m_end)
        , m_last(a_rhs.m_last)
        , m_sum (a_rhs.m_sum)
    {
        if (a_rhs.m_data == a_rhs.m_samples)
            m_data = m_samples;
        else {
            assert(N == 0);
            m_data = new T[capacity()];
        }

        memcpy(m_data, a_rhs.m_data, sizeof(T)*capacity());
    }

    #if __cplusplus >= 201103L
    basic_moving_average(basic_moving_average&& a_rhs)
        : base(a_rhs)
        , MASK  (a_rhs.MASK)
        , m_end (a_rhs.m_end)
        , m_last(a_rhs.m_last)
        , m_sum (a_rhs.m_sum)
    {
        if (a_rhs.m_data != a_rhs.m_samples) {
            assert(N == 0);
            m_data = a_rhs.m_data;
        } else {
            m_data = m_samples;
            memcpy(m_samples, a_rhs.m_samples, sizeof(T)*capacity());
        }
        // Reset the data pointer so that it's not
        a_rhs.m_data = nullptr;
        a_rhs.m_sum  = 0;
        a_rhs.m_last = 0;
        a_rhs.m_end  = 0;
    }
    #endif

    ~basic_moving_average() {
        if (m_data != m_samples)
            delete [] m_data;
    }

    void add(T sample) {
        m_last    = sample;
        T& oldest = m_data[m_end & MASK];
        m_sum    += sample;

        if (m_end > MASK)
           m_sum -= oldest;

        this->update_minmax(sample);

        oldest = sample;

        ++m_end;
    }

    void clear() {
        base::clear();
        if (m_data)
            memset(m_data, 0, capacity()*sizeof(T));
        m_sum  = 0;
        m_last = 0;
        m_end  = 0;
    }

    bool     empty()    const { return m_end == 0; }
    /// Capacity of the window
    size_t   capacity() const { return MASK+1; }
    /// Number of windowed items (<= capacity())
    size_t   size()     const { return m_end > MASK  ? capacity() : m_end; }
    /// Total number of samples processed since initialization
    size_t   total()    const { return m_end; }

    /// Access to raw samples
    const T* samples()  const { return m_data; }

    double   mean()     const { return likely(m_end) ? double(m_sum) / size() : 0.0; }
    T        sum()      const { return m_sum;  }
    T        last()     const { return m_last; }

    std::pair<T,T> minmax() const {
        if (unlikely(empty()))
            return std::make_pair
                (std::numeric_limits<T>::max(), std::numeric_limits<T>::min());
        return base::minmax();
    }

    T min() const { return base::min(); }
    T max() const { return base::max(); }

protected:
    template <typename D, typename U, bool F> friend class detail::minmax_impl;

    size_t  begin_idx()        const { return m_end - size(); }
    size_t  end_idx()          const { return m_end;          }
    T       data(size_t a_idx) const { return m_data[a_idx & MASK]; }

    const size_t    MASK;
    size_t          m_end;
    T               m_last;
    T               m_sum;
    T*              m_data;
    T               m_samples[N];
};

/**
 * Calculate a running weighted average of values on a given
 * windowing interval using exponential decay.
 */
class weighted_average {
    size_t m_sec_interval;  ///< Number of seconds in the averaging window
    size_t m_last_seconds;  ///< Last reported timeval.tv_sec.
    double m_last;          ///< Last reported value.

    double m_last_wavg;     ///< Last weighted average
    double m_denominator;   ///< Equals m_sec_interval*60

    void reset(size_t a_sec_interval) {
        interval(a_sec_interval);
        m_last_seconds = 0;
        m_last = m_last_wavg = 0;
    }

public:
    explicit weighted_average(size_t a_sec_interval = 15u) {
        reset(a_sec_interval);
    }

    /// Obtain weighted exponential average
    double calculate(size_t a_now_sec, double a_value) {
        return calculate_exp(a_now_sec, a_value);
    }

    /// Obtain exponential moving average
    double calculate_ema(size_t a_now_sec, double a_value) {
      auto fun = [=]() { return 2.0/(1.0+interval()); };
      return calculate(a_now_sec, a_value, fun);
    }

    /// Obtain weighted exponential average
    double calculate_exp(size_t a_now_sec, double a_value) {
      auto fun = [=]() { return exp(-(double)(a_now_sec - m_last_seconds) / m_denominator); };
      return calculate(a_now_sec, a_value, fun);
    }

    template <typename AlphaFun>
    double calculate(size_t a_now_sec, double a_value, const AlphaFun& fun) {
      double alpha    = fun();
      m_last_wavg     = a_value + alpha * (m_last_wavg - a_value);
      m_last          = a_value;
      m_last_seconds  = a_now_sec;
      return m_last_wavg;
    }

    /// Clear internal state
    void clear() { reset(m_sec_interval); }

    double last_value()     const { return m_last;      }
    double last_weighted()  const { return m_last_wavg; }

    /// Get windowing interval in seconds
    size_t interval()       const { return m_sec_interval; }

    /// Set windowing interval in seconds
    void interval(size_t a_sec_interval) {
        if (a_sec_interval == 0)
            throw std::out_of_range("Argument must be > 0!");
        m_sec_interval = a_sec_interval;
        m_denominator  = a_sec_interval * 60;
    }
};

} // namespace utxx
<|endoftext|>


<commit_before>///////////////////////////////////////////////////////////////////////////////
//
// File: TriangularMatrixStoragePolicy.hpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// 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.
//
// Description:
//
///////////////////////////////////////////////////////////////////////////////

#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_TRIANGULAR_MATRIX_STORAGE_POLICY_HPP
#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_TRIANGULAR_MATRIX_STORAGE_POLICY_HPP

#include <LibUtilities/LinearAlgebra/MatrixStoragePolicy.hpp>
#include <boost/call_traits.hpp>
#include "boost/tuple/tuple.hpp"

namespace Nektar
{
    template<typename DataType>
    class TriangularMatrixStoragePolicy
    {
        public:
            typedef typename boost::call_traits<DataType>::value_type GetValueReturnType;
            static DataType ZeroElement;

            static Array<OneD, DataType> Initialize()
            {
                return Array<OneD, DataType>();
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns)
            {
                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                return Array<OneD, DataType>(rows*(rows+1)/2);
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns,
                                                    typename boost::call_traits<DataType>::const_reference d)
            {
                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                return Array<OneD, DataType>(rows*(rows+1)/2, d);
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns,
                                                    const DataType* d)
            {
                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                return Array<OneD, DataType>(rows*(rows+1)/2, d);
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns,
                                                    const ConstArray<OneD, DataType>& d)
            {
                unsigned int size = rows*(rows+1)/2;

                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                ASSERTL0(size <= d.num_elements(),
                    std::string("An attempt has been made to create a triangular matrix of size ") +
                    boost::lexical_cast<std::string>(rows*(rows+1)/2) +
                    std::string(" but the array being used to populate it only has ") +
                    boost::lexical_cast<std::string>(d.num_elements()) +
                    std::string(" elements."));

                Array<OneD, DataType> result(size, d);
                return result;
            }
    };

    template<typename DataType>
    DataType TriangularMatrixStoragePolicy<DataType>::ZeroElement = DataType(0);

    template<typename DataType>
    class MatrixStoragePolicy<DataType, UpperTriangularMatrixTag> : public TriangularMatrixStoragePolicy<DataType>
    {
        public:
            typedef TriangularMatrixStoragePolicy<DataType> BaseType;
            typedef typename BaseType::GetValueReturnType GetValueReturnType;

            static typename boost::call_traits<DataType>::const_reference GetValue(unsigned int totalRows, unsigned int totalColumns,
                                                                             unsigned int curRow, unsigned int curColumn,
                                                                             const Array<OneD, DataType>& data)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to retrieve a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to retrieve a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                if( curRow <= curColumn )
                {
                    return data[CalculateIndex(totalRows, curRow, curColumn)];
                }
                else
                {
                    return BaseType::ZeroElement;
                }
            }

            static void SetValue(unsigned int totalRows, unsigned int totalColumns,
                                 unsigned int curRow, unsigned int curColumn,
                                 Array<OneD, DataType>& data, typename boost::call_traits<DataType>::const_reference d)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to set a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to set a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curRow <= curColumn, "Attemping to set element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::string>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                data[CalculateIndex(totalRows, curRow, curColumn)] = d;
            }

            static unsigned int CalculateIndex(unsigned int totalRows, unsigned int curRow, unsigned int curColumn)
            {
                return curColumn + (2*totalRows - curRow - 1)*(curRow)/2;
            }

            static boost::tuples::tuple<unsigned int, unsigned int>
            Advance(const unsigned int totalRows, const unsigned int totalColumns,
                    const unsigned int curRow, const unsigned int curColumn)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curRow <= curColumn, "Attemping to iterate through element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::string>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                unsigned int nextRow = curRow;
                unsigned int nextColumn = curColumn;

                if( nextColumn < totalColumns )
                {
                    ++nextColumn;
                }

                if( nextColumn >= totalColumns )
                {
                    ++nextRow;
                    nextColumn = nextRow;
                }

                if( nextRow >= totalRows )
                {
                    nextRow = std::numeric_limits<unsigned int>::max();
                    nextColumn = std::numeric_limits<unsigned int>::max();
                }

                return boost::tuples::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
            }
    };

    template<typename DataType>
    class MatrixStoragePolicy<DataType, LowerTriangularMatrixTag>
    {
        public:
            typedef TriangularMatrixStoragePolicy<DataType> BaseType;
            typedef typename BaseType::GetValueReturnType GetValueReturnType;

            static typename boost::call_traits<DataType>::const_reference GetValue(unsigned int totalRows, unsigned int totalColumns,
                                                                             unsigned int curRow, unsigned int curColumn,
                                                                             const Array<OneD, DataType>& data)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to retrieve a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to retrieve a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                if( curRow <= curColumn )
                {
                    return data[CalculateIndex(totalRows, curRow, curColumn)];
                }
                else
                {
                    return BaseType::ZeroElement;
                }
            }

            static void SetValue(unsigned int totalRows, unsigned int totalColumns,
                                 unsigned int curRow, unsigned int curColumn,
                                 Array<OneD, DataType>& data, typename boost::call_traits<DataType>::const_reference d)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to set a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to set a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curRow >= curColumn, "Attemping to set element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::string>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");

                data[CalculateIndex(totalRows, curRow, curColumn)] = d;
            }

            static unsigned int CalculateIndex(unsigned int totalRows, unsigned int curRow, unsigned int curColumn)
            {
                return curColumn + curRow*(curRow+1)/2;
            }

            static boost::tuples::tuple<unsigned int, unsigned int>
            Advance(const unsigned int totalRows, const unsigned int totalColumns,
                    const unsigned int curRow, const unsigned int curColumn)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");
                ASSERTL1(curRow >= curColumn, "Attemping to iterate through element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::String>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");

                unsigned int nextRow = curRow;
                unsigned int nextColumn = curColumn;

                if( nextColumn < curRow )
                {
                    ++nextColumn;
                }

                if( nextColumn >= curRow )
                {
                    ++nextRow;
                    nextColumn = 0;
                }

                if( nextRow >= totalRows )
                {
                    nextRow = std::numeric_limits<unsigned int>::max();
                    nextColumn = std::numeric_limits<unsigned int>::max();
                }

                return boost::tuples::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
            }
    };
}

#endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_TRIANGULAR_MATRIX_STORAGE_POLICY_HPP
<commit_msg>Changed one call to std::String to std::string<commit_after>///////////////////////////////////////////////////////////////////////////////
//
// File: TriangularMatrixStoragePolicy.hpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// 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.
//
// Description:
//
///////////////////////////////////////////////////////////////////////////////

#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_TRIANGULAR_MATRIX_STORAGE_POLICY_HPP
#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_TRIANGULAR_MATRIX_STORAGE_POLICY_HPP

#include <LibUtilities/LinearAlgebra/MatrixStoragePolicy.hpp>
#include <boost/call_traits.hpp>
#include "boost/tuple/tuple.hpp"

namespace Nektar
{
    template<typename DataType>
    class TriangularMatrixStoragePolicy
    {
        public:
            typedef typename boost::call_traits<DataType>::value_type GetValueReturnType;
            static DataType ZeroElement;

            static Array<OneD, DataType> Initialize()
            {
                return Array<OneD, DataType>();
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns)
            {
                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                return Array<OneD, DataType>(rows*(rows+1)/2);
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns,
                                                    typename boost::call_traits<DataType>::const_reference d)
            {
                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                return Array<OneD, DataType>(rows*(rows+1)/2, d);
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns,
                                                    const DataType* d)
            {
                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                return Array<OneD, DataType>(rows*(rows+1)/2, d);
            }

            static Array<OneD, DataType> Initialize(unsigned int rows, unsigned int columns,
                                                    const ConstArray<OneD, DataType>& d)
            {
                unsigned int size = rows*(rows+1)/2;

                ASSERTL0(rows==columns, "Triangular matrices must be square.");
                ASSERTL0(size <= d.num_elements(),
                    std::string("An attempt has been made to create a triangular matrix of size ") +
                    boost::lexical_cast<std::string>(rows*(rows+1)/2) +
                    std::string(" but the array being used to populate it only has ") +
                    boost::lexical_cast<std::string>(d.num_elements()) +
                    std::string(" elements."));

                Array<OneD, DataType> result(size, d);
                return result;
            }
    };

    template<typename DataType>
    DataType TriangularMatrixStoragePolicy<DataType>::ZeroElement = DataType(0);

    template<typename DataType>
    class MatrixStoragePolicy<DataType, UpperTriangularMatrixTag> : public TriangularMatrixStoragePolicy<DataType>
    {
        public:
            typedef TriangularMatrixStoragePolicy<DataType> BaseType;
            typedef typename BaseType::GetValueReturnType GetValueReturnType;

            static typename boost::call_traits<DataType>::const_reference GetValue(unsigned int totalRows, unsigned int totalColumns,
                                                                             unsigned int curRow, unsigned int curColumn,
                                                                             const Array<OneD, DataType>& data)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to retrieve a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to retrieve a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                if( curRow <= curColumn )
                {
                    return data[CalculateIndex(totalRows, curRow, curColumn)];
                }
                else
                {
                    return BaseType::ZeroElement;
                }
            }

            static void SetValue(unsigned int totalRows, unsigned int totalColumns,
                                 unsigned int curRow, unsigned int curColumn,
                                 Array<OneD, DataType>& data, typename boost::call_traits<DataType>::const_reference d)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to set a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to set a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curRow <= curColumn, "Attemping to set element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::string>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                data[CalculateIndex(totalRows, curRow, curColumn)] = d;
            }

            static unsigned int CalculateIndex(unsigned int totalRows, unsigned int curRow, unsigned int curColumn)
            {
                return curColumn + (2*totalRows - curRow - 1)*(curRow)/2;
            }

            static boost::tuples::tuple<unsigned int, unsigned int>
            Advance(const unsigned int totalRows, const unsigned int totalColumns,
                    const unsigned int curRow, const unsigned int curColumn)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curRow <= curColumn, "Attemping to iterate through element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::string>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                unsigned int nextRow = curRow;
                unsigned int nextColumn = curColumn;

                if( nextColumn < totalColumns )
                {
                    ++nextColumn;
                }

                if( nextColumn >= totalColumns )
                {
                    ++nextRow;
                    nextColumn = nextRow;
                }

                if( nextRow >= totalRows )
                {
                    nextRow = std::numeric_limits<unsigned int>::max();
                    nextColumn = std::numeric_limits<unsigned int>::max();
                }

                return boost::tuples::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
            }
    };

    template<typename DataType>
    class MatrixStoragePolicy<DataType, LowerTriangularMatrixTag>
    {
        public:
            typedef TriangularMatrixStoragePolicy<DataType> BaseType;
            typedef typename BaseType::GetValueReturnType GetValueReturnType;

            static typename boost::call_traits<DataType>::const_reference GetValue(unsigned int totalRows, unsigned int totalColumns,
                                                                             unsigned int curRow, unsigned int curColumn,
                                                                             const Array<OneD, DataType>& data)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to retrieve a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to retrieve a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");

                if( curRow <= curColumn )
                {
                    return data[CalculateIndex(totalRows, curRow, curColumn)];
                }
                else
                {
                    return BaseType::ZeroElement;
                }
            }

            static void SetValue(unsigned int totalRows, unsigned int totalColumns,
                                 unsigned int curRow, unsigned int curColumn,
                                 Array<OneD, DataType>& data, typename boost::call_traits<DataType>::const_reference d)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to set a value from row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to set a value from column " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " upper triangular matrix.");
                ASSERTL1(curRow >= curColumn, "Attemping to set element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::string>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");

                data[CalculateIndex(totalRows, curRow, curColumn)] = d;
            }

            static unsigned int CalculateIndex(unsigned int totalRows, unsigned int curRow, unsigned int curColumn)
            {
                return curColumn + curRow*(curRow+1)/2;
            }

            static boost::tuples::tuple<unsigned int, unsigned int>
            Advance(const unsigned int totalRows, const unsigned int totalColumns,
                    const unsigned int curRow, const unsigned int curColumn)
            {
                ASSERTL1(totalRows == totalColumns, "Triangular matrices must be square.");
                ASSERTL1(curRow < totalRows, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curRow) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");
                ASSERTL1(curColumn < totalColumns, "Attemping to iterate through an element on row " +
                    boost::lexical_cast<std::string>(curColumn) + " of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");
                ASSERTL1(curRow >= curColumn, "Attemping to iterate through element (" +
                    boost::lexical_cast<std::string>(curRow) + ", " +
                    boost::lexical_cast<std::string>(curColumn) + ") of a (" +
                    boost::lexical_cast<std::string>(totalRows) + ", " +
                    boost::lexical_cast<std::string>(totalColumns) + " lower triangular matrix.");

                unsigned int nextRow = curRow;
                unsigned int nextColumn = curColumn;

                if( nextColumn < curRow )
                {
                    ++nextColumn;
                }

                if( nextColumn >= curRow )
                {
                    ++nextRow;
                    nextColumn = 0;
                }

                if( nextRow >= totalRows )
                {
                    nextRow = std::numeric_limits<unsigned int>::max();
                    nextColumn = std::numeric_limits<unsigned int>::max();
                }

                return boost::tuples::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
            }
    };
}

#endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_TRIANGULAR_MATRIX_STORAGE_POLICY_HPP
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: adrparse.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 20:10:25 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _ADRPARSE_HXX
#define _ADRPARSE_HXX

#ifndef INCLUDED_SVLDLLAPI_H
#include "svtools/svldllapi.h"
#endif

#ifndef _LIST_HXX
#include <tools/list.hxx>
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif

//============================================================================
struct SvAddressEntry_Impl
{
    UniString m_aAddrSpec;
    UniString m_aRealName;

    SvAddressEntry_Impl() {};
    SvAddressEntry_Impl(UniString const & rTheAddrSpec,
                        UniString const & rTheRealName):
        m_aAddrSpec(rTheAddrSpec), m_aRealName(rTheRealName) {}
};

//============================================================================
DECLARE_LIST(SvAddressList_Impl, SvAddressEntry_Impl *)

//============================================================================
class SVL_DLLPUBLIC SvAddressParser
{
    friend class SvAddressParser_Impl;

    SvAddressEntry_Impl m_aFirst;
    SvAddressList_Impl m_aRest;
    bool m_bHasFirst;

public:
    SvAddressParser(UniString const & rInput);

    ~SvAddressParser();

    sal_Int32 Count() const { return m_bHasFirst ? m_aRest.Count() + 1 : 0; }

    inline UniString const & GetEmailAddress(sal_Int32 nIndex) const;

    inline UniString const &GetRealName(sal_Int32 nIndex) const;

    /** Create an RFC 822 <mailbox> (i.e., 'e-mail address').

        @param rPhrase  Either an empty string (the <mailbox> will have no
        <phrase> an will be of the form <addr-spec>), or some text that will
        become the <phrase> part of a <phrase route-addr> form <mailbox>.  Non
        US-ASCII characters within the text are put into a <qouted-string>
        verbatim, so the result may actually not be a valid RFC 822 <mailbox>,
        but a more human-readable representation.

        @param rAddrSpec  A valid RFC 822 <addr-spec>.  (An RFC 822 <mailbox>
        including a <route> cannot be created by this method.)

        @param rMailbox  If this method returns true, this parameter returns
        the created RFC 822 <mailbox> (rather, a more human-readable
        representation thereof).  Otherwise, this parameter is not modified.

        @return  True, if rAddrSpec is a valid RFC 822 <addr-spec>.
     */
    static bool createRFC822Mailbox(String const & rPhrase,
                                    String const & rAddrSpec,
                                    String & rMailbox);
};

inline UniString const & SvAddressParser::GetEmailAddress(sal_Int32 nIndex)
    const
{
    return nIndex == 0 ? m_aFirst.m_aAddrSpec :
                         m_aRest.GetObject(nIndex - 1)->m_aAddrSpec;
}

inline UniString const & SvAddressParser::GetRealName(sal_Int32 nIndex) const
{
    return nIndex == 0 ? m_aFirst.m_aRealName :
                         m_aRest.GetObject(nIndex - 1)->m_aRealName;
}

#endif // _ADRPARSE_HXX

<commit_msg>INTEGRATION: CWS changefileheader (1.4.546); FILE MERGED 2008/04/01 15:44:17 thb 1.4.546.3: #i85898# Stripping all external header guards 2008/04/01 12:43:05 thb 1.4.546.2: #i85898# Stripping all external header guards 2008/03/31 13:00:45 rt 1.4.546.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: adrparse.hxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _ADRPARSE_HXX
#define _ADRPARSE_HXX

#include "svtools/svldllapi.h"
#include <tools/list.hxx>
#include <tools/string.hxx>

//============================================================================
struct SvAddressEntry_Impl
{
    UniString m_aAddrSpec;
    UniString m_aRealName;

    SvAddressEntry_Impl() {};
    SvAddressEntry_Impl(UniString const & rTheAddrSpec,
                        UniString const & rTheRealName):
        m_aAddrSpec(rTheAddrSpec), m_aRealName(rTheRealName) {}
};

//============================================================================
DECLARE_LIST(SvAddressList_Impl, SvAddressEntry_Impl *)

//============================================================================
class SVL_DLLPUBLIC SvAddressParser
{
    friend class SvAddressParser_Impl;

    SvAddressEntry_Impl m_aFirst;
    SvAddressList_Impl m_aRest;
    bool m_bHasFirst;

public:
    SvAddressParser(UniString const & rInput);

    ~SvAddressParser();

    sal_Int32 Count() const { return m_bHasFirst ? m_aRest.Count() + 1 : 0; }

    inline UniString const & GetEmailAddress(sal_Int32 nIndex) const;

    inline UniString const &GetRealName(sal_Int32 nIndex) const;

    /** Create an RFC 822 <mailbox> (i.e., 'e-mail address').

        @param rPhrase  Either an empty string (the <mailbox> will have no
        <phrase> an will be of the form <addr-spec>), or some text that will
        become the <phrase> part of a <phrase route-addr> form <mailbox>.  Non
        US-ASCII characters within the text are put into a <qouted-string>
        verbatim, so the result may actually not be a valid RFC 822 <mailbox>,
        but a more human-readable representation.

        @param rAddrSpec  A valid RFC 822 <addr-spec>.  (An RFC 822 <mailbox>
        including a <route> cannot be created by this method.)

        @param rMailbox  If this method returns true, this parameter returns
        the created RFC 822 <mailbox> (rather, a more human-readable
        representation thereof).  Otherwise, this parameter is not modified.

        @return  True, if rAddrSpec is a valid RFC 822 <addr-spec>.
     */
    static bool createRFC822Mailbox(String const & rPhrase,
                                    String const & rAddrSpec,
                                    String & rMailbox);
};

inline UniString const & SvAddressParser::GetEmailAddress(sal_Int32 nIndex)
    const
{
    return nIndex == 0 ? m_aFirst.m_aAddrSpec :
                         m_aRest.GetObject(nIndex - 1)->m_aAddrSpec;
}

inline UniString const & SvAddressParser::GetRealName(sal_Int32 nIndex) const
{
    return nIndex == 0 ? m_aFirst.m_aRealName :
                         m_aRest.GetObject(nIndex - 1)->m_aRealName;
}

#endif // _ADRPARSE_HXX

<|endoftext|>


<commit_before>#include <debugger/luathread.h>
#include <debugger/impl.h>
#include <debugger/thunk.h>

namespace vscode
{
	static int get_stacklevel(lua_State* L)
	{
		lua::Debug ar;
		int n;
		for (n = 0; lua_getstack(L, n + 1, (lua_Debug*)&ar) != 0; ++n)
		{
		}
		return n;
	}

	static int get_stacklevel(lua_State* L, int pos)
	{
		lua::Debug ar;
		if (lua_getstack(L, pos, (lua_Debug*)&ar) != 0) {
			for (; lua_getstack(L, pos + 1, (lua_Debug*)&ar) != 0; ++pos)
			{
			}
		}
		else if (pos > 0) {
			for (--pos; pos > 0 && lua_getstack(L, pos, (lua_Debug*)&ar) == 0; --pos)
			{
			}
		}
		return pos;
	}

	static void debugger_hook(luathread* thread, lua_State *L, lua::Debug *ar)
	{
		if (!thread->enable) return;
		thread->dbg->hook(thread, L, ar);
	}

	static void debugger_panic(luathread* thread, lua_State *L)
	{
		if (!thread->enable) return;
		thread->dbg->exception(thread, L);
	}

	luathread::luathread(int id, debugger_impl* dbg, lua_State* L)
		: id(id)
		, enable(true)
		, release(false)
		, dbg(dbg)
		, L(L)
		, oldpanic(lua_atpanic(L, 0))
		, thunk_hook((lua_Hook)thunk_create_hook(
			reinterpret_cast<intptr_t>(this),
			reinterpret_cast<intptr_t>(&debugger_hook)
		))
		, thunk_panic((lua_CFunction)thunk_create_panic(
			reinterpret_cast<intptr_t>(this),
			reinterpret_cast<intptr_t>(&debugger_panic),
			reinterpret_cast<intptr_t>(oldpanic)
		))
		, step_(step::in)
		, stepping_target_level_(0)
		, stepping_current_level_(0)
		, stepping_lua_state_(NULL)
		, cur_bp_(0)
		, cur_func_(0)
		, has_source_(false)
		, ob_(id)
	{
		install_hook(LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE);
		lua_atpanic(L, thunk_panic);
	}

	luathread::~luathread()
	{
		if (release) return;
		lua_sethook(L, 0, 0, 0);
		lua_atpanic(L, oldpanic);
		thunk_destory(thunk_hook);
		thunk_destory(thunk_panic);
	}

	void luathread::install_hook(int mask)
	{
		lua_sethook(L, thunk_hook, mask, 0);
	}

	void luathread::release_thread()
	{
		release = true;
	}

	void luathread::enable_thread()
	{
		enable = true;
	}

	void luathread::disable_thread()
	{
		enable = false;
	}

	void luathread::set_step(step step)
	{
		step_ = step;
	}

	bool luathread::is_step(step step)
	{
		return step_ == step;
	}

	bool luathread::check_step(lua_State* L, lua::Debug* ar)
	{
		if (is_step(luathread::step::in)) return true;
		return stepping_lua_state_ == L && stepping_current_level_ <= stepping_target_level_;
	}

	void luathread::step_in()
	{
		set_step(step::in);
	}

	void luathread::step_over(lua_State* L, lua::Debug* ar)
	{
		set_step(step::over);
		stepping_target_level_ = stepping_current_level_ = get_stacklevel(L);
		stepping_lua_state_ = L;
	}

	void luathread::step_out(lua_State* L, lua::Debug* ar)
	{
		set_step(step::out);
		stepping_target_level_ = stepping_current_level_ = get_stacklevel(L);
		stepping_target_level_--;
		stepping_lua_state_ = L;
	}

	void luathread::hook_call(lua_State* L, lua::Debug* ar)
	{
		has_source_ = false;
		cur_func_ = nullptr;
		cur_bp_ = nullptr;
		if (stepping_lua_state_ == L) {
			stepping_current_level_++;
		}
	}

	void luathread::hook_return(lua_State* L, lua::Debug* ar)
	{
		has_source_ = false;
		cur_func_ = nullptr;
		cur_bp_ = nullptr;
		if (stepping_lua_state_ == L) {
			stepping_current_level_ = get_stacklevel(L, stepping_current_level_) - 1;
		}
	}

	void luathread::hook_line(lua_State* L, lua::Debug* ar, breakpoint& breakpoint)
	{
		if (!has_source_) {
			has_source_ = true;
			cur_func_ = breakpoint.get(L, ar);
			if (cur_func_) {
				cur_bp_ = cur_func_->update_bp(&breakpoint);
			}
			else {
				cur_func_ = nullptr;
			}
		}
	}

	void luathread::update_breakpoint()
	{
		if (cur_func_ && !cur_bp_) {
			has_source_ = false;
		}
	}

	void luathread::reset_frame(lua_State* L)
	{
		ob_.reset(L);
	}

	void luathread::evaluate(lua_State* L, lua::Debug *ar, debugger_impl* dbg, rprotocol& req, int frameId)
	{
		ob_.evaluate(L, ar, dbg, req, frameId);
	}

	void luathread::new_frame(lua_State* L, debugger_impl* dbg, rprotocol& req, int frameId)
	{
		ob_.new_frame(L, dbg, req, frameId);
	}

	void luathread::get_variable(lua_State* L, debugger_impl* dbg, rprotocol& req, int64_t valueId, int frameId)
	{
		ob_.get_variable(L, dbg, req, valueId, frameId);
	}

	void luathread::set_variable(lua_State* L, debugger_impl* dbg, rprotocol& req, int64_t valueId, int frameId)
	{
		ob_.set_variable(L, dbg, req, valueId, frameId);
	}
}
<commit_msg>忘了校验有效性<commit_after>#include <debugger/luathread.h>
#include <debugger/impl.h>
#include <debugger/thunk.h>

namespace vscode
{
	static int get_stacklevel(lua_State* L)
	{
		lua::Debug ar;
		int n;
		for (n = 0; lua_getstack(L, n + 1, (lua_Debug*)&ar) != 0; ++n)
		{
		}
		return n;
	}

	static int get_stacklevel(lua_State* L, int pos)
	{
		lua::Debug ar;
		if (lua_getstack(L, pos, (lua_Debug*)&ar) != 0) {
			for (; lua_getstack(L, pos + 1, (lua_Debug*)&ar) != 0; ++pos)
			{
			}
		}
		else if (pos > 0) {
			for (--pos; pos > 0 && lua_getstack(L, pos, (lua_Debug*)&ar) == 0; --pos)
			{
			}
		}
		return pos;
	}

	static void debugger_hook(luathread* thread, lua_State *L, lua::Debug *ar)
	{
		if (!thread->enable) return;
		thread->dbg->hook(thread, L, ar);
	}

	static void debugger_panic(luathread* thread, lua_State *L)
	{
		if (!thread->enable) return;
		thread->dbg->exception(thread, L);
	}

	luathread::luathread(int id, debugger_impl* dbg, lua_State* L)
		: id(id)
		, enable(true)
		, release(false)
		, dbg(dbg)
		, L(L)
		, oldpanic(lua_atpanic(L, 0))
		, thunk_hook((lua_Hook)thunk_create_hook(
			reinterpret_cast<intptr_t>(this),
			reinterpret_cast<intptr_t>(&debugger_hook)
		))
		, thunk_panic((lua_CFunction)thunk_create_panic(
			reinterpret_cast<intptr_t>(this),
			reinterpret_cast<intptr_t>(&debugger_panic),
			reinterpret_cast<intptr_t>(oldpanic)
		))
		, step_(step::in)
		, stepping_target_level_(0)
		, stepping_current_level_(0)
		, stepping_lua_state_(NULL)
		, cur_bp_(0)
		, cur_func_(0)
		, has_source_(false)
		, ob_(id)
	{
		install_hook(LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE);
		lua_atpanic(L, thunk_panic);
	}

	luathread::~luathread()
	{
		if (release) return;
		lua_sethook(L, 0, 0, 0);
		lua_atpanic(L, oldpanic);
		thunk_destory(thunk_hook);
		thunk_destory(thunk_panic);
	}

	void luathread::install_hook(int mask)
	{
		lua_sethook(L, thunk_hook, mask, 0);
	}

	void luathread::release_thread()
	{
		release = true;
	}

	void luathread::enable_thread()
	{
		enable = true;
	}

	void luathread::disable_thread()
	{
		enable = false;
	}

	void luathread::set_step(step step)
	{
		step_ = step;
	}

	bool luathread::is_step(step step)
	{
		return step_ == step;
	}

	bool luathread::check_step(lua_State* L, lua::Debug* ar)
	{
		if (is_step(luathread::step::in)) return true;
		return stepping_lua_state_ == L && stepping_current_level_ <= stepping_target_level_;
	}

	void luathread::step_in()
	{
		set_step(step::in);
	}

	void luathread::step_over(lua_State* L, lua::Debug* ar)
	{
		set_step(step::over);
		stepping_target_level_ = stepping_current_level_ = get_stacklevel(L);
		stepping_lua_state_ = L;
	}

	void luathread::step_out(lua_State* L, lua::Debug* ar)
	{
		set_step(step::out);
		stepping_target_level_ = stepping_current_level_ = get_stacklevel(L);
		stepping_target_level_--;
		stepping_lua_state_ = L;
	}

	void luathread::hook_call(lua_State* L, lua::Debug* ar)
	{
		has_source_ = false;
		cur_func_ = nullptr;
		cur_bp_ = nullptr;
		if (stepping_lua_state_ == L) {
			stepping_current_level_++;
		}
	}

	void luathread::hook_return(lua_State* L, lua::Debug* ar)
	{
		has_source_ = false;
		cur_func_ = nullptr;
		cur_bp_ = nullptr;
		if (stepping_lua_state_ == L) {
			stepping_current_level_ = get_stacklevel(L, stepping_current_level_) - 1;
		}
	}

	void luathread::hook_line(lua_State* L, lua::Debug* ar, breakpoint& breakpoint)
	{
		if (!has_source_) {
			has_source_ = true;
			cur_func_ = breakpoint.get(L, ar);
			if (cur_func_ && cur_func_->vaild) {
				cur_bp_ = cur_func_->update_bp(&breakpoint);
			}
			else {
				cur_func_ = nullptr;
			}
		}
	}

	void luathread::update_breakpoint()
	{
		if (cur_func_ && !cur_bp_) {
			has_source_ = false;
		}
	}

	void luathread::reset_frame(lua_State* L)
	{
		ob_.reset(L);
	}

	void luathread::evaluate(lua_State* L, lua::Debug *ar, debugger_impl* dbg, rprotocol& req, int frameId)
	{
		ob_.evaluate(L, ar, dbg, req, frameId);
	}

	void luathread::new_frame(lua_State* L, debugger_impl* dbg, rprotocol& req, int frameId)
	{
		ob_.new_frame(L, dbg, req, frameId);
	}

	void luathread::get_variable(lua_State* L, debugger_impl* dbg, rprotocol& req, int64_t valueId, int frameId)
	{
		ob_.get_variable(L, dbg, req, valueId, frameId);
	}

	void luathread::set_variable(lua_State* L, debugger_impl* dbg, rprotocol& req, int64_t valueId, int frameId)
	{
		ob_.set_variable(L, dbg, req, valueId, frameId);
	}
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: polygn3d.hxx,v $
 * $Revision: 1.3 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _E3D_POLYGON3D_HXX
#define _E3D_POLYGON3D_HXX

#include <svx/obj3d.hxx>
#include "svx/svxdllapi.h"

class SVX_DLLPUBLIC E3dPolygonObj : public E3dCompoundObject
{
private:
    // Parameter
    basegfx::B3DPolyPolygon aPolyPoly3D;
    basegfx::B3DPolyPolygon aPolyNormals3D;
    basegfx::B2DPolyPolygon aPolyTexture2D;
    BOOL            bLineOnly;

    SVX_DLLPRIVATE void CreateDefaultNormals();
    SVX_DLLPRIVATE void CreateDefaultTexture();

public:
    void SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D);
    void SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D);
    void SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyPoly2D);

    TYPEINFO();

    E3dPolygonObj(
        E3dDefaultAttributes& rDefault,
        const basegfx::B3DPolyPolygon& rPolyPoly3D,
        BOOL bLinOnly=FALSE);
    E3dPolygonObj(
        E3dDefaultAttributes& rDefault,
        const basegfx::B3DPolyPolygon& rPolyPoly3D,
        const basegfx::B3DPolyPolygon& rPolyNormals3D,
        BOOL bLinOnly=FALSE);
    E3dPolygonObj(
        E3dDefaultAttributes& rDefault,
        const basegfx::B3DPolyPolygon& rPolyPoly3D,
        const basegfx::B3DPolyPolygon& rPolyNormals3D,
        const basegfx::B2DPolyPolygon& rPolyTexture2D,
        BOOL bLinOnly=FALSE);

    E3dPolygonObj();
    virtual ~E3dPolygonObj();

    const basegfx::B3DPolyPolygon& GetPolyPolygon3D() const { return aPolyPoly3D; }
    const basegfx::B3DPolyPolygon& GetPolyNormals3D() const { return aPolyNormals3D; }
    const basegfx::B2DPolyPolygon& GetPolyTexture2D() const { return aPolyTexture2D; }

    virtual UINT16 GetObjIdentifier() const;
    virtual SdrObject* DoConvertToPolyObj(BOOL bBezier) const;

    virtual void operator=(const SdrObject&);

    // Geometrieerzeugung
    virtual void CreateGeometry();

    // Give out simple line geometry
    virtual basegfx::B3DPolyPolygon Get3DLineGeometry() const;

    // LineOnly?
    BOOL GetLineOnly() { return bLineOnly; }
    void SetLineOnly(BOOL bNew);
};

#endif          // _E3D_POLYGON3D_HXX
<commit_msg>INTEGRATION: CWS aw033 (1.2.76); FILE MERGED 2008/05/14 13:56:32 aw 1.2.76.2: RESYNC: (1.2-1.3); FILE MERGED 2007/05/24 10:05:56 aw 1.2.76.1: applied patches to migrated headers<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: polygn3d.hxx,v $
 * $Revision: 1.4 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _E3D_POLYGON3D_HXX
#define _E3D_POLYGON3D_HXX

#include <svx/obj3d.hxx>
#include "svx/svxdllapi.h"

class SVX_DLLPUBLIC E3dPolygonObj : public E3dCompoundObject
{
private:
    // #110094# DrawContact section
    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact();

    // Parameter
    basegfx::B3DPolyPolygon aPolyPoly3D;
    basegfx::B3DPolyPolygon aPolyNormals3D;
    basegfx::B2DPolyPolygon aPolyTexture2D;
    BOOL            bLineOnly;

    SVX_DLLPRIVATE void CreateDefaultNormals();
    SVX_DLLPRIVATE void CreateDefaultTexture();

public:
    void SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D);
    void SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D);
    void SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyPoly2D);

    TYPEINFO();

    E3dPolygonObj(
        E3dDefaultAttributes& rDefault,
        const basegfx::B3DPolyPolygon& rPolyPoly3D,
        BOOL bLinOnly=FALSE);
    E3dPolygonObj(
        E3dDefaultAttributes& rDefault,
        const basegfx::B3DPolyPolygon& rPolyPoly3D,
        const basegfx::B3DPolyPolygon& rPolyNormals3D,
        BOOL bLinOnly=FALSE);
    E3dPolygonObj(
        E3dDefaultAttributes& rDefault,
        const basegfx::B3DPolyPolygon& rPolyPoly3D,
        const basegfx::B3DPolyPolygon& rPolyNormals3D,
        const basegfx::B2DPolyPolygon& rPolyTexture2D,
        BOOL bLinOnly=FALSE);

    E3dPolygonObj();
    virtual ~E3dPolygonObj();

    const basegfx::B3DPolyPolygon& GetPolyPolygon3D() const { return aPolyPoly3D; }
    const basegfx::B3DPolyPolygon& GetPolyNormals3D() const { return aPolyNormals3D; }
    const basegfx::B2DPolyPolygon& GetPolyTexture2D() const { return aPolyTexture2D; }

    virtual UINT16 GetObjIdentifier() const;
    virtual SdrObject* DoConvertToPolyObj(BOOL bBezier) const;

    virtual void operator=(const SdrObject&);

    // Geometrieerzeugung
    virtual void CreateGeometry();

    // Give out simple line geometry
    virtual basegfx::B3DPolyPolygon Get3DLineGeometry() const;

    // LineOnly?
    BOOL GetLineOnly() { return bLineOnly; }
    void SetLineOnly(BOOL bNew);
};

#endif          // _E3D_POLYGON3D_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sdtaaitm.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: vg $ $Date: 2007-04-11 16:12:42 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _SDTAAITM_HXX
#define _SDTAAITM_HXX

#ifndef _SFXINTITEM_HXX //autogen
#include <svtools/intitem.hxx>
#endif

#ifndef _SVDDEF_HXX //autogen
#include <svx/svddef.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

class SVX_DLLPUBLIC SdrTextAniAmountItem: public SfxInt16Item {
public:
    TYPEINFO();
    SdrTextAniAmountItem(INT16 nVal=0): SfxInt16Item(SDRATTR_TEXT_ANIAMOUNT,nVal) {}
    SdrTextAniAmountItem(SvStream& rIn): SfxInt16Item(SDRATTR_TEXT_ANIAMOUNT,rIn) {}
    virtual SfxPoolItem* Clone(SfxItemPool* pPool=NULL) const;
    virtual SfxPoolItem* Create(SvStream& rIn, USHORT nVer) const;
    virtual FASTBOOL HasMetrics() const;
    virtual FASTBOOL ScaleMetrics(long nMul, long nDiv);

    virtual SfxItemPresentation GetPresentation(SfxItemPresentation ePres, SfxMapUnit eCoreMetric, SfxMapUnit ePresMetric, String& rText, const IntlWrapper * = 0) const;
};

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.2.466); FILE MERGED 2008/04/01 15:49:36 thb 1.2.466.3: #i85898# Stripping all external header guards 2008/04/01 12:46:50 thb 1.2.466.2: #i85898# Stripping all external header guards 2008/03/31 14:18:15 rt 1.2.466.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: sdtaaitm.hxx,v $
 * $Revision: 1.3 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _SDTAAITM_HXX
#define _SDTAAITM_HXX

#include <svtools/intitem.hxx>
#include <svx/svddef.hxx>
#include "svx/svxdllapi.h"

class SVX_DLLPUBLIC SdrTextAniAmountItem: public SfxInt16Item {
public:
    TYPEINFO();
    SdrTextAniAmountItem(INT16 nVal=0): SfxInt16Item(SDRATTR_TEXT_ANIAMOUNT,nVal) {}
    SdrTextAniAmountItem(SvStream& rIn): SfxInt16Item(SDRATTR_TEXT_ANIAMOUNT,rIn) {}
    virtual SfxPoolItem* Clone(SfxItemPool* pPool=NULL) const;
    virtual SfxPoolItem* Create(SvStream& rIn, USHORT nVer) const;
    virtual FASTBOOL HasMetrics() const;
    virtual FASTBOOL ScaleMetrics(long nMul, long nDiv);

    virtual SfxItemPresentation GetPresentation(SfxItemPresentation ePres, SfxMapUnit eCoreMetric, SfxMapUnit ePresMetric, String& rText, const IntlWrapper * = 0) const;
};

#endif
<|endoftext|>