package context import ( "errors" ) /* (1) Definitions ---------------------------------------------------------*/ /* (1) Default values */ const DefaultMin = 0x00f0 const DefaultMax = 0x0fff const DefaultThr = 0x000a /* (2) Struct attributes */ type T struct { win float64; // 'timeid' window size min uint16; // minimum scha depth max uint16; // maximum scha depth thr uint16; // scha depth threshold } /* (3) Constructor * * @win Window size for 'timeid' package * @min [OPT] Minimum scha depth * @thr [OPT] scha depth threshold before renewal * @max [OPT] Maximum scha depth * * @return outName outDesc * ---------------------------------------------------------*/ func Create(win float64, optional... uint16) (*T, error) { var inst = new(T); /* (1) Window size error */ if win < 0 { return nil, errors.New("Window size must be positive and is negative") } inst.win = win; /* (2) Default values */ inst.min = DefaultMin inst.thr = DefaultThr inst.max = DefaultMax /* (3) Optional 'min' */ if len(optional) > 0 { if optional[0] < 0x0f { return nil, errors.New("Minimum depth must be greater than 0x0f (decimal 15) for consistency issues") } inst.min = optional[0]; } /* (4) Optional 'thr' */ if len(optional) > 1 { inst.thr = optional[1]; } /* (5) Optional 'max' */ if len(optional) > 2 { if optional[2] <= inst.min+inst.thr { return nil, errors.New("Minimum depth must be greater than 0x0f (decimal 15) for consistency issues") } inst.max = optional[2]; } return inst, nil } /* (4) Getters */ func (c T) Window() float64 { return c.win } func (c T) MinDepth() uint16 { return c.min } func (c T) MaxDepth() uint16 { return c.max } func (c T) DepthThreshold() uint16 { return c.thr }