github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/examples/immtodoapp/gen_todo_app_immutableGen.go (about)

     1  // Code generated by immutableGen. DO NOT EDIT.
     2  
     3  package immtodoapp
     4  
     5  //immutableVet:skipFile
     6  
     7  import (
     8  	"myitcv.io/immutable"
     9  )
    10  
    11  //
    12  // itemS is an immutable type and has the following template:
    13  //
    14  // 	[]*item
    15  //
    16  type itemS struct {
    17  	theSlice []*item
    18  	mutable  bool
    19  	__tmpl   _Imm_itemS
    20  }
    21  
    22  var _ immutable.Immutable = new(itemS)
    23  var _ = new(itemS).__tmpl
    24  
    25  func newItemS(s ...*item) *itemS {
    26  	c := make([]*item, len(s))
    27  	copy(c, s)
    28  
    29  	return &itemS{
    30  		theSlice: c,
    31  	}
    32  }
    33  
    34  func newItemSLen(l int) *itemS {
    35  	c := make([]*item, l)
    36  
    37  	return &itemS{
    38  		theSlice: c,
    39  	}
    40  }
    41  
    42  func (m *itemS) Mutable() bool {
    43  	return m.mutable
    44  }
    45  
    46  func (m *itemS) Len() int {
    47  	if m == nil {
    48  		return 0
    49  	}
    50  
    51  	return len(m.theSlice)
    52  }
    53  
    54  func (m *itemS) Get(i int) *item {
    55  	return m.theSlice[i]
    56  }
    57  
    58  func (m *itemS) AsMutable() *itemS {
    59  	if m == nil {
    60  		return nil
    61  	}
    62  
    63  	if m.Mutable() {
    64  		return m
    65  	}
    66  
    67  	res := m.dup()
    68  	res.mutable = true
    69  
    70  	return res
    71  }
    72  
    73  func (m *itemS) dup() *itemS {
    74  	resSlice := make([]*item, len(m.theSlice))
    75  
    76  	for i := range m.theSlice {
    77  		resSlice[i] = m.theSlice[i]
    78  	}
    79  
    80  	res := &itemS{
    81  		theSlice: resSlice,
    82  	}
    83  
    84  	return res
    85  }
    86  
    87  func (m *itemS) AsImmutable(v *itemS) *itemS {
    88  	if m == nil {
    89  		return nil
    90  	}
    91  
    92  	if v == m {
    93  		return m
    94  	}
    95  
    96  	m.mutable = false
    97  	return m
    98  }
    99  
   100  func (m *itemS) Range() []*item {
   101  	if m == nil {
   102  		return nil
   103  	}
   104  
   105  	return m.theSlice
   106  }
   107  
   108  func (m *itemS) WithMutable(f func(mi *itemS)) *itemS {
   109  	res := m.AsMutable()
   110  	f(res)
   111  	res = res.AsImmutable(m)
   112  
   113  	return res
   114  }
   115  
   116  func (m *itemS) WithImmutable(f func(mi *itemS)) *itemS {
   117  	prev := m.mutable
   118  	m.mutable = false
   119  	f(m)
   120  	m.mutable = prev
   121  
   122  	return m
   123  }
   124  
   125  func (m *itemS) Set(i int, v *item) *itemS {
   126  	if m.mutable {
   127  		m.theSlice[i] = v
   128  		return m
   129  	}
   130  
   131  	res := m.dup()
   132  	res.theSlice[i] = v
   133  
   134  	return res
   135  }
   136  
   137  func (m *itemS) Append(v ...*item) *itemS {
   138  	if m.mutable {
   139  		m.theSlice = append(m.theSlice, v...)
   140  		return m
   141  	}
   142  
   143  	res := m.dup()
   144  	res.theSlice = append(res.theSlice, v...)
   145  
   146  	return res
   147  }
   148  func (s *itemS) IsDeeplyNonMutable(seen map[interface{}]bool) bool {
   149  	if s == nil {
   150  		return true
   151  	}
   152  
   153  	if s.Mutable() {
   154  		return false
   155  	}
   156  	if s.Len() == 0 {
   157  		return true
   158  	}
   159  
   160  	if seen == nil {
   161  		return s.IsDeeplyNonMutable(make(map[interface{}]bool))
   162  	}
   163  
   164  	if seen[s] {
   165  		return true
   166  	}
   167  
   168  	seen[s] = true
   169  
   170  	for _, v := range s.theSlice {
   171  		if v != nil && !v.IsDeeplyNonMutable(seen) {
   172  			return false
   173  		}
   174  	}
   175  	return true
   176  }
   177  
   178  //
   179  // item is an immutable type and has the following template:
   180  //
   181  // 	struct {
   182  // 		name string
   183  // 	}
   184  //
   185  type item struct {
   186  	_name string
   187  
   188  	mutable bool
   189  	__tmpl  _Imm_item
   190  }
   191  
   192  var _ immutable.Immutable = new(item)
   193  var _ = new(item).__tmpl
   194  
   195  func (s *item) AsMutable() *item {
   196  	if s.Mutable() {
   197  		return s
   198  	}
   199  
   200  	res := *s
   201  	res.mutable = true
   202  	return &res
   203  }
   204  
   205  func (s *item) AsImmutable(v *item) *item {
   206  	if s == nil {
   207  		return nil
   208  	}
   209  
   210  	if s == v {
   211  		return s
   212  	}
   213  
   214  	s.mutable = false
   215  	return s
   216  }
   217  
   218  func (s *item) Mutable() bool {
   219  	return s.mutable
   220  }
   221  
   222  func (s *item) WithMutable(f func(si *item)) *item {
   223  	res := s.AsMutable()
   224  	f(res)
   225  	res = res.AsImmutable(s)
   226  
   227  	return res
   228  }
   229  
   230  func (s *item) WithImmutable(f func(si *item)) *item {
   231  	prev := s.mutable
   232  	s.mutable = false
   233  	f(s)
   234  	s.mutable = prev
   235  
   236  	return s
   237  }
   238  func (s *item) IsDeeplyNonMutable(seen map[interface{}]bool) bool {
   239  	if s == nil {
   240  		return true
   241  	}
   242  
   243  	if s.Mutable() {
   244  		return false
   245  	}
   246  
   247  	if seen == nil {
   248  		return s.IsDeeplyNonMutable(make(map[interface{}]bool))
   249  	}
   250  
   251  	if seen[s] {
   252  		return true
   253  	}
   254  
   255  	seen[s] = true
   256  	return true
   257  }
   258  func (s *item) name() string {
   259  	return s._name
   260  }
   261  
   262  // setName is the setter for Name()
   263  func (s *item) setName(n string) *item {
   264  	if s.mutable {
   265  		s._name = n
   266  		return s
   267  	}
   268  
   269  	res := *s
   270  	res._name = n
   271  	return &res
   272  }