#-------------------------------------------------------------------------------
# Helper to inject common virtual methods for equations of state
#-------------------------------------------------------------------------------
import inspect
from PYB11Generator import *
from spheralDimensions import *
dims = spheralDimensions()

@PYB11ignore
class FileIOAbstractMethods:

    #...........................................................................
    # Abstract interface (primitives)
    @PYB11const
    def pathExists(self,
                   pathName = "const std::string"):
        return "bool"

    # These types require specially mangled names to avoid bad casts
    for T, Tmangle in [("unsigned", "unsigned_int"),
                       ("size_t", "size_t"),
                       ("int", "int"),
                       ("bool", "bool"),
                       ("double", "double"),
                       ("std::string", "string"),
                       ("std::vector<int>", "VectorInt"),
                       ("std::vector<double>", "VectorDouble"),
                       ("std::vector<std::string>", "VectorString")]:
        exec("""
@PYB11pycppname("write")
@PYB11noconvert
def write{Tmangle}(self,
                   value = "const {T}&",
                   pathName = "const std::string"):
    "Write {T}"
    return "void"

@PYB11pycppname("read")
@PYB11const
@PYB11noconvert
def read{Tmangle}(self,
                    value = "{T}&",
                    pathName = "const std::string"):
    "Read {T}"
    return "void"

""".format(T = T,
           Tmangle = Tmangle))

    # More primitive types
    types = []
    for ndim in range(1,4):
        types += ["Dim<%i>::Vector" % ndim,
                  "Dim<%i>::Tensor" % ndim,
                  "Dim<%i>::SymTensor" % ndim,
                  "Dim<%i>::ThirdRankTensor" % ndim]
    for T in types:
        exec("""
@PYB11pycppname("write")
@PYB11noconvert
def write{Tmangle}(self,
                     value = "const {T}&",
                     pathName = "const std::string"):
    "Write {T}"
    return "void"

@PYB11pycppname("read")
@PYB11const
@PYB11noconvert
def read{Tmangle}(self,
                    value = "{T}&",
                    pathName = "const std::string"):
    "Read {T}"
    return "void"
""".format(T = T,
           Tmangle = T.replace(":", "_").replace("<", "_").replace(">", "_")))
