Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:56

0001 #pragma once
0002 
0003 #include <cstddef> // for size_t
0004 #include <vector>
0005 
0006 
0007 class Pattern
0008 {
0009  public:
0010 
0011    typedef typename std::vector<double>::iterator iterator;
0012    typedef typename std::vector<double>::const_iterator const_iterator;
0013 
0014    Pattern ()
0015       : m_weight (0)
0016       {
0017       }
0018 
0019    ~Pattern ()
0020       {
0021       }
0022 
0023    Pattern (const Pattern& other)
0024       {
0025          m_input.assign (std::begin (other.m_input), std::end (other.m_input));
0026          m_output.assign (std::begin (other.m_output), std::end (other.m_output));
0027          m_weight = other.m_weight;
0028       }
0029 
0030    Pattern (Pattern&& other)
0031       {
0032          m_input = std::move (other.m_input);
0033          m_output = std::move (other.m_output);
0034          m_weight = other.m_weight;
0035       }
0036 
0037    Pattern& operator= (const Pattern& other)
0038       {
0039          m_input.assign (std::begin (other.input ()), std::end (other.input ()));
0040          m_output.assign (std::begin (other.output ()), std::end (other.output ()));
0041          m_weight = other.m_weight;
0042          return *this;
0043       }
0044 
0045    template <typename ItValue>
0046       Pattern (ItValue inputBegin, ItValue inputEnd, ItValue outputBegin, ItValue outputEnd, double _weight = 1.0)
0047       : m_input (inputBegin, inputEnd)
0048       , m_output (outputBegin, outputEnd)
0049       , m_weight (_weight)
0050    {
0051    }
0052 
0053    template <typename ItValue>
0054       Pattern (ItValue inputBegin, ItValue inputEnd, double outputValue, double _weight = 1.0)
0055       : m_input (inputBegin, inputEnd)
0056       , m_weight (_weight)
0057    {
0058       m_output.push_back (outputValue);
0059    }
0060 
0061    template <typename InputContainer, typename OutputContainer>
0062       Pattern (InputContainer& _input, OutputContainer& _output, double _weight = 1.0)
0063       : m_input (std::begin (_input), std::end (_input))
0064       , m_output (std::begin (_output), std::end (_output))
0065       , m_weight (_weight)
0066    {
0067    }
0068 
0069    const_iterator beginInput () const { return m_input.begin (); }
0070    const_iterator endInput   () const  { return m_input.end (); }
0071    const_iterator beginOutput () const  { return m_output.begin (); }
0072    const_iterator endOutput   () const  { return m_output.end (); }
0073 
0074    double weight () const { return m_weight; }
0075    void weight (double w) { m_weight = w; }
0076 
0077    size_t inputSize () const { return m_input.size (); }
0078    size_t outputSize () const { return m_output.size (); }
0079 
0080    void addInput (double value) { m_input.push_back (value); }
0081    void addOutput (double value) { m_output.push_back (value); }
0082 
0083    std::vector<double>& input  () { return m_input; }
0084    std::vector<double>& output () { return m_output; }
0085    const std::vector<double>& input  () const { return m_input; }
0086    const std::vector<double>& output () const { return m_output; }
0087 
0088  private:
0089    std::vector<double> m_input;
0090    std::vector<double> m_output;
0091    double m_weight;
0092 };