github.com/hedzr/evendeep@v0.4.8/flags/cms/copymergestrategy.go (about)

     1  //go:generate go install golang.org/x/tools/cmd/stringer@latest
     2  //go:generate stringer -type=CopyMergeStrategy -linecomment
     3  
     4  package cms
     5  
     6  // CopyMergeStrategy enum.
     7  type CopyMergeStrategy int
     8  
     9  // CopyMergeStrategies an array of CopyMergeStrategy.
    10  type CopyMergeStrategies []CopyMergeStrategy
    11  
    12  // Parse decodes the given string and return the matched CopyMergeStrategy value.
    13  func (i CopyMergeStrategy) Parse(s string) CopyMergeStrategy {
    14  	for ix, str := range _CopyMergeStrategy_map {
    15  		if s == str {
    16  			return ix
    17  		}
    18  	}
    19  	return InvalidStrategy
    20  }
    21  
    22  const (
    23  	// Default the public fields will be copied.
    24  	Default CopyMergeStrategy = iota // std
    25  	// Ignore the ignored fields will be ignored in all scenes
    26  	//
    27  	// // the 'ignore' Tag inside target field cannot block copying on itself.
    28  	Ignore // -
    29  	// Must the must-be-copied fields will always be copied to the target.
    30  	Must // must
    31  
    32  	// ClearIfEq the target field will be reset/clear to zero if it
    33  	// equals to the source.
    34  	// Just for struct fields.
    35  	ClearIfEq CopyMergeStrategy = iota + 10 // cleareq
    36  
    37  	// KeepIfNotEq the source field will not be copied if it does not
    38  	// equal to the target.
    39  	// Just for struct fields.
    40  	KeepIfNotEq // keepneq
    41  
    42  	// ClearIfInvalid the target field will be reset/clear to zero
    43  	// if source is invalid.
    44  	// default is ON.
    45  	ClearIfInvalid // clearinvalid
    46  
    47  	// ClearIfMissed clear/reset the target field if source field
    48  	// not found.
    49  	ClearIfMissed // clearmissed
    50  
    51  	// NoOmit never omit any source fields.
    52  	NoOmit CopyMergeStrategy = iota + 20 - 5 // noomit
    53  	// OmitIfEmpty is both OmitIfSourceNil + OmitIfSourceZero.
    54  	OmitIfEmpty // omitempty
    55  	// OmitIfNil the target field will be kept if source is nil.
    56  	OmitIfNil // omitnil
    57  	// OmitIfZero the target field will be kept if source is zero.
    58  	OmitIfZero // omitzero
    59  
    60  	// NoOmitTarget never omit any target fields.
    61  	NoOmitTarget CopyMergeStrategy = iota + 30 - 9 // noomittgt
    62  	// OmitIfTargetEmpty is both OmitIfTargetNil + OmitIfTargetZero.
    63  	OmitIfTargetEmpty // omitemptytgt
    64  	// OmitIfTargetNil keeps the target field if it is nil.
    65  	OmitIfTargetNil // omitniltgt
    66  	// OmitIfTargetZero keeps the target field if it is zero.
    67  	OmitIfTargetZero // omitzerotgt
    68  
    69  	// SliceCopy the source slice will be set or duplicated to the target.
    70  	// the target slice will be lost.
    71  	SliceCopy CopyMergeStrategy = iota + 50 - 13 // slicecopy
    72  	// SliceCopyAppend the source slice will be appended into the target.
    73  	// The original value in the target will be kept.
    74  	SliceCopyAppend // slicecopyappend
    75  	// SliceMerge the source slice will be appended into the target
    76  	// if anyone of them is not exists inside the target slice.
    77  	//
    78  	// The duplicated items in the target original slice have no changes.
    79  	//
    80  	// The uniqueness checking is only applied to each source slice items.
    81  	SliceMerge // slicemerge
    82  
    83  	// MapCopy do copy source map to the target.
    84  	MapCopy CopyMergeStrategy = iota + 70 - 16 // mapcopy
    85  	// MapMerge try to merge each fields inside source map recursively,
    86  	// even if it's a slice, a pointer, another sub-map, and so on.
    87  	MapMerge // mapmerge
    88  
    89  	// Flat copy a pointer instead of its object pointed.
    90  	Flat CopyMergeStrategy = iota + 80 - 17 // flat
    91  
    92  	//
    93  	// // --- Globally settings ---.
    94  	//
    95  
    96  	// The following constants are reserved for the future purpose.
    97  	// All of them should NOT be used in your user-side codes.
    98  
    99  	// UnexportedToo _.
   100  	UnexportedToo CopyMergeStrategy = iota + 90 - 18 // private
   101  
   102  	// ByOrdinal will be applied to struct, map and slice.
   103  	// As to slice, it is standard and unique choice.
   104  	ByOrdinal // byordinal
   105  	// ByName will be applied to struct or map.
   106  	ByName // byname
   107  
   108  	// MaxStrategy is a mark to indicate the max value of all available
   109  	// CopyMergeStrategies.
   110  	MaxStrategy
   111  
   112  	// reserved:
   113  
   114  	ftf100 CopyMergeStrategy = iota + 100
   115  	ftf110 CopyMergeStrategy = iota + 110
   116  	ftf120 CopyMergeStrategy = iota + 120
   117  	ftf130 CopyMergeStrategy = iota + 130
   118  	ftf140 CopyMergeStrategy = iota + 140
   119  	ftf150 CopyMergeStrategy = iota + 150
   120  	ftf160 CopyMergeStrategy = iota + 160
   121  	ftf170 CopyMergeStrategy = iota + 170
   122  
   123  	// InvalidStrategy for algorithm purpose.
   124  	InvalidStrategy = CopyMergeStrategy(-1)
   125  )
   126  
   127  // Limit values of implementation-specific int type.
   128  const (
   129  
   130  	// https://stackoverflow.com/questions/6878590/the-maximum-value-for-an-int-type-in-go
   131  	// https://github.com/golang/go/blob/master/src/math/const.go#L39
   132  	// intSize = 32 << (^uint(0) >> 63) // 32 or 64
   133  	// MaxInt  = 1<<(intSize-1) - 1
   134  	// MinInt  = -1 << (intSize - 1).
   135  
   136  	// MaxInt = int.max (2^63-1 or 2^31-1 for CPU Bit Size = 32bits).
   137  	MaxInt = int(^uint(0) >> 1)
   138  	// MinInt = int.max (-2^63).
   139  	MinInt = -MaxInt - 1
   140  )