go-hep.org/x/hep@v0.38.1/groot/rbase/attline.go (about)

     1  // Copyright ©2017 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package rbase
     6  
     7  import (
     8  	"reflect"
     9  
    10  	"go-hep.org/x/hep/groot/rbytes"
    11  	"go-hep.org/x/hep/groot/rcolors"
    12  	"go-hep.org/x/hep/groot/root"
    13  	"go-hep.org/x/hep/groot/rtypes"
    14  	"go-hep.org/x/hep/groot/rvers"
    15  )
    16  
    17  type AttLine struct {
    18  	Color int16
    19  	Style int16
    20  	Width int16
    21  }
    22  
    23  func NewAttLine() *AttLine {
    24  	return &AttLine{
    25  		Color: rcolors.Blue + 2,
    26  		Style: 1,
    27  		Width: 1,
    28  	}
    29  }
    30  
    31  func (*AttLine) Class() string {
    32  	return "TAttLine"
    33  }
    34  
    35  func (*AttLine) RVersion() int16 {
    36  	return rvers.AttLine
    37  }
    38  
    39  func (a *AttLine) MarshalROOT(w *rbytes.WBuffer) (int, error) {
    40  	if w.Err() != nil {
    41  		return 0, w.Err()
    42  	}
    43  
    44  	hdr := w.WriteHeader(a.Class(), a.RVersion())
    45  	w.WriteI16(a.Color)
    46  	w.WriteI16(a.Style)
    47  	w.WriteI16(a.Width)
    48  	return w.SetHeader(hdr)
    49  }
    50  
    51  func (a *AttLine) UnmarshalROOT(r *rbytes.RBuffer) error {
    52  	if r.Err() != nil {
    53  		return r.Err()
    54  	}
    55  
    56  	hdr := r.ReadHeader(a.Class(), a.RVersion())
    57  
    58  	a.Color = r.ReadI16()
    59  	a.Style = r.ReadI16()
    60  	a.Width = r.ReadI16()
    61  
    62  	r.CheckHeader(hdr)
    63  	return r.Err()
    64  }
    65  
    66  func (a *AttLine) RMembers() []rbytes.Member {
    67  	return []rbytes.Member{
    68  		{Name: "fLineColor", Value: &a.Color},
    69  		{Name: "fLineStyle", Value: &a.Style},
    70  		{Name: "fLineWidth", Value: &a.Width},
    71  	}
    72  }
    73  
    74  func init() {
    75  	f := func() reflect.Value {
    76  		o := NewAttLine()
    77  		return reflect.ValueOf(o)
    78  	}
    79  	rtypes.Factory.Add("TAttLine", f)
    80  }
    81  
    82  var (
    83  	_ root.Object        = (*AttLine)(nil)
    84  	_ rbytes.Marshaler   = (*AttLine)(nil)
    85  	_ rbytes.Unmarshaler = (*AttLine)(nil)
    86  )