from abc import abstractmethod

__author__ = "Jonathan Hale"


class DdlPrimitive:
    """
    An OpenDDL primitive structure.
    """

    def __init__(self, data_type, data, name=None, vector_size=0):
        """
        Constructor
        :param data_type: primitive data type (see pyddl.enum.PrimitiveType)
        :param data: list of values. If vector_size != 0, the list should contain tuples
        :param name: name of the primitive structure
        :param vector_size: size of the contained vectors
        """
        self.data_type = data_type
        self.name = name
        self.vector_size = vector_size
        self.data = data

    def is_simple_primitive(self):
        return len(self.data) == 1 and self.vector_size <= 4


class DdlStructure:
    """
    An OpenDDL structure.
    """

    def __init__(self, name):
        self.structures = []
        self.properties = dict()
        self.name = name


class DdlDocument:
    """
    An OpenDDL document.
    """

    def __init__(self):
        self.structures = []


class DdlWriter:
    """
    Abstract class for classes responsible for writing OpenDdlDocuments.
    """

    def __init__(self, document):
        self.doc = document

    def get_document(self):
        """
        :return: document to be written by this writer.
        """
        return self.doc

    @abstractmethod
    def write(self, filename):
        """
        Write the writers document to a specified file.
        :param file: file to write to
        :return: nothing
        """
        pass


class DdlTextWriter(DdlWriter):
    """
    OpenDdlWriter which writes OpenDdlDocuments in human-readable text form.
    """

    def __init__(self, document):
        DdlWriter.__init__(self, document)

    def write(self, filename):
        # TODO: not implemented yet!
        pass


# Space reserved for a specification based OpenDdlBinaryWriter ;)
# Hope there will be some specification for it some day.

@@ -826,20 +826,52 @@
 _(self, 
-name
+identifier, name=None, structures=%5B%5D
 ):%0A     
@@ -891,18 +891,26 @@
 tures = 
-%5B%5D
+structures
 %0A       
@@ -948,27 +948,600 @@
    self.
-name = name
+identifier = identifier%0A        self.name = name%0A%0A    def is_simple_structure(self):%0A        %22%22%22%0A        A structure is simple if it contains exactly one primitive and has no properties or name.%0A        :return: true if this structure is simple%0A        %22%22%22%0A        if len(self.structures) != 1:%0A            return False%0A        if len(self.properties) != 0:%0A            return False%0A        if self.name is not None:%0A            return False%0A        if not isinstance(self.structures%5B0%5D, DdlPrimitive):%0A            return False%0A%0A        return self.structures%5B0%5D.is_simple_primitive()
 %0A%0A%0Aclass

Implement DdlStructure