@@ -52,132 +52,6 @@ source "$(dirname "${BASH_SOURCE[0]}")/util.sh"
52
52
# Used for creating unique names for extras and storage maps.
53
53
MVM_COUNTER=0
54
54
55
- # Array mvm, the default. Provides an iteration helper that sends all
56
- # the array values to the iteration callback.
57
-
58
- function mvm_mvc_array_constructor() {
59
- local array_var_name
60
- array_var_name=${1} ; shift
61
-
62
- declare -g -a " ${array_var_name} "
63
-
64
- local -n array_ref=${array_var_name}
65
- array_ref=()
66
- }
67
-
68
- function mvm_mvc_array_destructor() {
69
- local array_var_name
70
- array_var_name=${1} ; shift
71
-
72
- unset " ${array_var_name} "
73
- }
74
-
75
- function mvm_mvc_array_adder() {
76
- local array_var_name
77
- array_var_name=${1} ; shift
78
- # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
79
- local -n array_ref=${array_var_name}
80
-
81
- array_ref+=( " ${@ } " )
82
- }
83
-
84
- # iteration_helper is optional
85
- function mvm_mvc_array_iteration_helper() {
86
- local key array_var_name callback
87
- key=${1} ; shift
88
- array_var_name=${1} ; shift
89
- callback=${1} ; shift
90
- # rest are extra args passed to cb
91
-
92
- # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
93
- local -n array_ref=${array_var_name}
94
- " ${callback} " " ${@ } " " ${key} " " ${array_var_name} " " ${array_ref[@]} "
95
- }
96
-
97
- # Map mvm. When adding elements to the mvc, it is expected that the
98
- # number of items passed will be even. Odd elements will be used as
99
- # keys, even elements will be used as values.
100
- #
101
- # No iteration helper.
102
-
103
- function mvm_mvc_map_constructor() {
104
- local map_var_name
105
- map_var_name=${1} ; shift
106
-
107
- declare -g -A " ${map_var_name} "
108
-
109
- local -n map_ref=${map_var_name}
110
- map_ref=()
111
- }
112
-
113
- function mvm_mvc_map_destructor() {
114
- local map_var_name
115
- map_var_name=${1} ; shift
116
-
117
- unset " ${map_var_name} "
118
- }
119
-
120
- function mvm_mvc_map_adder() {
121
- local map_var_name
122
- map_var_name=${1} ; shift
123
- # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
124
- local -n map_ref=${map_var_name}
125
-
126
- while [[ ${# } -gt 1 ]]; do
127
- # shellcheck disable=SC2034 # it's a reference to external variable
128
- map_ref[" ${1} " ]=${2}
129
- shift 2
130
- done
131
- }
132
-
133
- # Set mvm. Behaves like array mvm, but all elements in each set are
134
- # unique and the order of elements is not guaranteed to be the same as
135
- # order of insertions.
136
-
137
- function mvm_mvc_set_constructor() {
138
- local set_var_name
139
- set_var_name=${1} ; shift
140
-
141
- declare -g -A " ${set_var_name} "
142
-
143
- # shellcheck disable=SC2178 # shellcheck does not grok refs
144
- local -n set_ref=${set_var_name}
145
- set_ref=()
146
- }
147
-
148
- function mvm_mvc_set_destructor() {
149
- local set_var_name
150
- set_var_name=${1}
151
-
152
- unset " ${set_var_name} "
153
- }
154
-
155
- function mvm_mvc_set_adder() {
156
- local set_var_name
157
- set_var_name=${1} ; shift
158
-
159
- # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
160
- local -n set_ref=${set_var_name}
161
- while [[ ${# } -gt 0 ]]; do
162
- set_ref[" ${1} " ]=x
163
- shift
164
- done
165
- }
166
-
167
- # iteration_helper is optional
168
- function mvm_mvc_set_iteration_helper() {
169
- local key map_var_name callback
170
-
171
- key=${1} ; shift
172
- set_var_name=${1} ; shift
173
- callback=${1} ; shift
174
- # rest are extra args passed to cb
175
-
176
- # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
177
- local -n set_ref=${set_var_name}
178
- " ${callback} " " ${@ } " " ${key} " " ${set_var_name} " " ${! set_ref[@]} "
179
- }
180
-
181
55
# mvm API
182
56
183
57
# Creates a new mvm with a passed name, optionally type and
@@ -570,4 +444,130 @@ function mvm_debug_disable() {
570
444
unset " MVM_DEBUG_NAMES[${mvm_var_name} ]"
571
445
}
572
446
447
+ # Array mvm, the default. Provides an iteration helper that sends all
448
+ # the array values to the iteration callback.
449
+
450
+ function mvm_mvc_array_constructor() {
451
+ local array_var_name
452
+ array_var_name=${1} ; shift
453
+
454
+ declare -g -a " ${array_var_name} "
455
+
456
+ local -n array_ref=${array_var_name}
457
+ array_ref=()
458
+ }
459
+
460
+ function mvm_mvc_array_destructor() {
461
+ local array_var_name
462
+ array_var_name=${1} ; shift
463
+
464
+ unset " ${array_var_name} "
465
+ }
466
+
467
+ function mvm_mvc_array_adder() {
468
+ local array_var_name
469
+ array_var_name=${1} ; shift
470
+ # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
471
+ local -n array_ref=${array_var_name}
472
+
473
+ array_ref+=( " ${@ } " )
474
+ }
475
+
476
+ # iteration_helper is optional
477
+ function mvm_mvc_array_iteration_helper() {
478
+ local key array_var_name callback
479
+ key=${1} ; shift
480
+ array_var_name=${1} ; shift
481
+ callback=${1} ; shift
482
+ # rest are extra args passed to cb
483
+
484
+ # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
485
+ local -n array_ref=${array_var_name}
486
+ " ${callback} " " ${@ } " " ${key} " " ${array_var_name} " " ${array_ref[@]} "
487
+ }
488
+
489
+ # Map mvm. When adding elements to the mvc, it is expected that the
490
+ # number of items passed will be even. Odd elements will be used as
491
+ # keys, even elements will be used as values.
492
+ #
493
+ # No iteration helper.
494
+
495
+ function mvm_mvc_map_constructor() {
496
+ local map_var_name
497
+ map_var_name=${1} ; shift
498
+
499
+ declare -g -A " ${map_var_name} "
500
+
501
+ local -n map_ref=${map_var_name}
502
+ map_ref=()
503
+ }
504
+
505
+ function mvm_mvc_map_destructor() {
506
+ local map_var_name
507
+ map_var_name=${1} ; shift
508
+
509
+ unset " ${map_var_name} "
510
+ }
511
+
512
+ function mvm_mvc_map_adder() {
513
+ local map_var_name
514
+ map_var_name=${1} ; shift
515
+ # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
516
+ local -n map_ref=${map_var_name}
517
+
518
+ while [[ ${# } -gt 1 ]]; do
519
+ # shellcheck disable=SC2034 # it's a reference to external variable
520
+ map_ref[" ${1} " ]=${2}
521
+ shift 2
522
+ done
523
+ }
524
+
525
+ # Set mvm. Behaves like array mvm, but all elements in each set are
526
+ # unique and the order of elements is not guaranteed to be the same as
527
+ # order of insertions.
528
+
529
+ function mvm_mvc_set_constructor() {
530
+ local set_var_name
531
+ set_var_name=${1} ; shift
532
+
533
+ declare -g -A " ${set_var_name} "
534
+
535
+ # shellcheck disable=SC2178 # shellcheck does not grok refs
536
+ local -n set_ref=${set_var_name}
537
+ set_ref=()
538
+ }
539
+
540
+ function mvm_mvc_set_destructor() {
541
+ local set_var_name
542
+ set_var_name=${1}
543
+
544
+ unset " ${set_var_name} "
545
+ }
546
+
547
+ function mvm_mvc_set_adder() {
548
+ local set_var_name
549
+ set_var_name=${1} ; shift
550
+
551
+ # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
552
+ local -n set_ref=${set_var_name}
553
+ while [[ ${# } -gt 0 ]]; do
554
+ set_ref[" ${1} " ]=x
555
+ shift
556
+ done
557
+ }
558
+
559
+ # iteration_helper is optional
560
+ function mvm_mvc_set_iteration_helper() {
561
+ local key map_var_name callback
562
+
563
+ key=${1} ; shift
564
+ set_var_name=${1} ; shift
565
+ callback=${1} ; shift
566
+ # rest are extra args passed to cb
567
+
568
+ # shellcheck disable=SC2178 # shellcheck doesn't grok references to arrays
569
+ local -n set_ref=${set_var_name}
570
+ " ${callback} " " ${@ } " " ${key} " " ${set_var_name} " " ${! set_ref[@]} "
571
+ }
572
+
573
573
fi
0 commit comments