//#####################################################################
// Copyright 2022, Craig Schroeder.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
// Class SYMBOLIC_SPARSE_MATRIX_HELPER
//##################################################################### 
#ifndef __SYMBOLIC_SPARSE_MATRIX_HELPER__
#define __SYMBOLIC_SPARSE_MATRIX_HELPER__

#include <Core/Arrays/ARRAY.h>
#include <Core/Symbolics/SYMBOLIC.h>
#include <Core/Symbolics/SYMBOLIC_BASE.h>
#include <string>
namespace PhysBAM{

template<class T> class OCTAVE_OUTPUT;
template<class T> class KRYLOV_SYSTEM_BASE;
template<class T> class KRYLOV_VECTOR_BASE;
class SYMBOLIC;

class SYMBOLIC_SPARSE_MATRIX_HELPER:public SYMBOLIC_BASE
{
public:
    ARRAY<std::pair<int,double>> coeffs;

    SYMBOLIC_SPARSE_MATRIX_HELPER()=default;
    SYMBOLIC_SPARSE_MATRIX_HELPER(const SYMBOLIC_SPARSE_MATRIX_HELPER& t)=default;
    
    ~SYMBOLIC_SPARSE_MATRIX_HELPER()=default;
    void Set(double x) override;
    void Print(double x,std::ostream& o) const override;
    SYMBOLIC_BASE* Clone() const override;

    void Unary(double x,const SYMBOLIC& a,type_1 op) override;
    void Binary(double x,const SYMBOLIC& a,const SYMBOLIC& b,type_2 op) override;
};

inline void Set_Var(SYMBOLIC& s,int i)
{
    dynamic_cast<SYMBOLIC_SPARSE_MATRIX_HELPER*>(s.z)->coeffs.Append({i,1});
}

inline const ARRAY<std::pair<int,double>>& Get_Coeffs(const SYMBOLIC& s)
{
    return dynamic_cast<const SYMBOLIC_SPARSE_MATRIX_HELPER*>(s.z)->coeffs;
}
}

#endif
