Skip to content

Commit ee8b751

Browse files
committed
Format the template
1 parent dd1dbf8 commit ee8b751

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

rosidl_gen/templates/message.dot

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ const {{=refObjectArrayType}} = StructType({
269269
{{/* Define the wrapper class for the message. */}}
270270
class {{=objectWrapper}} {
271271
constructor(other, willCheckConsistency = false) {
272-
this._initMembers(willCheckConsistency);
272+
this._initialize(willCheckConsistency);
273273
this._setDefaults();
274274

275275
{{/* Construct `this` from `other`. */}}
@@ -296,6 +296,7 @@ class {{=objectWrapper}} {
296296
this.freeze();
297297
}
298298

299+
{{/* Set default values if the fields have. */}}
299300
_setDefaults() {
300301
{{~ it.spec.fields :field}}
301302
{{/* Set the flag of initialization. */}}
@@ -318,7 +319,7 @@ class {{=objectWrapper}} {
318319
{{~}}
319320
}
320321

321-
_initMembers(willCheckConsistency) {
322+
_initialize(willCheckConsistency) {
322323
this._willCheckConsistency = willCheckConsistency;
323324
this._wrapperFields = {};
324325
this._refObject = new {{=refObjectType}}();
@@ -368,7 +369,7 @@ class {{=objectWrapper}} {
368369
return this._refObject.ref();
369370
}
370371

371-
{{ /*Allocate the memory following the struct of the message*/ }}
372+
{{ /*Assign values to the ref object. */ }}
372373
freeze(own = false, checkConsistency = false) {
373374
{{~ it.spec.fields :field}}
374375
{{? field.type.isPrimitiveType && !field.type.isArray}}
@@ -409,23 +410,25 @@ class {{=objectWrapper}} {
409410
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
410411
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
411412
}
413+
{{?? field.type.isArray && field.type.isPrimitiveType && isTypedArrayType(field.type)}}
414+
if (!own) {
415+
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
416+
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
417+
} else {
418+
this._wrapperFields.{{=field.name}}.fill({{=getTypedArrayName(field.type)}}.from([]));
419+
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
420+
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
421+
}
412422
{{?? field.type.isArray && !field.type.isPrimitiveType && field.type.isFixedSizeArray}}
413423
for (let i = 0; i < {{=field.type.arraySize}}; i++) {
414424
if (this._wrapperFields.{{=field.name}}.data[i]) {
415425
this._wrapperFields.{{=field.name}}.data[i].freeze(own, checkConsistency);
416426
this._refObject.{{=field.name}}[i] = this._wrapperFields.{{=field.name}}.data[i].refObject;
417427
}
418428
}
419-
{{?? !field.type.isPrimitiveType || field.type.isArray}}
429+
{{?? field.type.isArray || !field.type.isPrimitiveType}}
420430
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
421431
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
422-
{{? field.type.isArray && field.type.isPrimitiveType}}
423-
if (own) {
424-
this._wrapperFields.{{=field.name}}.fill({{=getTypedArrayName(field.type)}}.from([]));
425-
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
426-
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
427-
}
428-
{{?}}
429432
{{?? field.type.type === 'string' && it.spec.msgName !== 'String'}}
430433
if (own) {
431434
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
@@ -470,7 +473,7 @@ class {{=objectWrapper}} {
470473
for (let i = 0; i < {{=field.type.arraySize}}; i++) {
471474
this._wrapperFields.{{=field.name}}.data[i].copyRefObject(refObject.{{=field.name}}[i]);
472475
}
473-
{{?? !field.type.isPrimitiveType || field.type.isArray}}
476+
{{?? field.type.isArray || !field.type.isPrimitiveType}}
474477
this._wrapperFields.{{=field.name}}.copyRefObject(refObject.{{=field.name}});
475478
{{?? field.type.type === 'string' && it.spec.msgName !== 'String'}}
476479
this._wrapperFields.{{=field.name}}.data = refObject.{{=field.name}}.data;
@@ -565,6 +568,7 @@ class {{=objectWrapper}} {
565568
if (value.length !== {{=field.type.arraySize}}) {
566569
throw new RangeError('The length of the array must be {{=field.type.arraySize}}.');
567570
}
571+
568572
{{?}}
569573
{{?field.type.isArray && field.type.isUpperBound}}
570574
if (value.length > {{=field.type.arraySize}}) {
@@ -660,7 +664,7 @@ class {{=arrayWrapper}} {
660664
fill(values) {
661665
{{? usePlainTypedArray}}
662666
if (Array.isArray(values)) {
663-
{{/* Convert JavaScript array. */}}
667+
{{/* Convert to TypedArray. */}}
664668
this._wrappers = new {{=currentTypedArray}}(values);
665669
} else {
666670
this._wrappers = values;
@@ -840,14 +844,14 @@ class {{=arrayWrapper}} {
840844
}
841845

842846
{{? it.spec.constants != undefined && it.spec.constants.length}}
843-
{{/* Define constants ({{=it.spec.constants.length}} in total). */}}
844-
{{~ it.spec.constants :c}}
845-
{{? c.type === "string"}}
846-
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: "{{=c.value}}", writable: false, enumerable: true, configurable: true});
847-
{{??}}
848-
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: {{=c.value}}, writable: false, enumerable: true, configurable: true});
849-
{{?}}
850-
{{~}}
847+
{{/* Define constants ({{=it.spec.constants.length}} in total). */}}
848+
{{~ it.spec.constants :c}}
849+
{{? c.type === "string"}}
850+
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: "{{=c.value}}", writable: false, enumerable: true, configurable: true});
851+
{{??}}
852+
Object.defineProperty({{=objectWrapper}}, "{{=c.name}}", {value: {{=c.value}}, writable: false, enumerable: true, configurable: true});
853+
{{?}}
854+
{{~}}
851855
{{?}}
852856

853857
module.exports = {{=objectWrapper}};

0 commit comments

Comments
 (0)