from gk_library import *
import sys


#######################################################################
## Basic input module
#######################################################################
class basic_input(object):
    def __init__(self, input_stream = sys.stdin):
        self.i_stream = input_stream

    def read(self, size = None):
        if size == None:
            return self.parse(self.i_stream.read())
        else:
            return self.parse(self.i_stream.read(size))

    def parse(self, item):
        return item

#######################################################################
## Basic GDS input stream
#######################################################################
class basic_gds_input(basic_input):
    def __init__(self, input_stream = sys.stdin):
        basic_input.__init__(self,input_stream)
        self.library = None
        self.scaling = 1.0
        self.layer_map = {}
        self.prefix = ""

    def read(self):
        return self.parse()
        

    def parse(self):
        return self.parse_library()

    def parse_library(self):
        self.library = gds_library("IMPORT")
        self.__parse_library__()
        return self.library

    def map_layer(self, layer_number):
        if layer_number in self.layer_map:
            L = self.layer_map[layer_number]
            if isinstance(L, gds_layer):
                return L
            else:
                return gds_layer(L)
        else:
            return gds_layer(layer_number)

    def make_structure_name(self, name):
        return self.prefix + name

#################################################
## Element Types
#################################################
Type_Boundary = 1
Type_Path = 2
Type_SRef = 3
Type_ARef = 4
Type_Label = 5
Type_Box = 6