From f3c691502599d50478511558b205c720b409bf7a Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 24 Aug 2016 09:45:11 -0400 Subject: [PATCH 1/2] Added ComponentDatatype.fromName --- CHANGES.md | 2 +- Source/Core/ComponentDatatype.js | 31 +++++++++++++++++++++++++++++ Specs/Core/ComponentDatatypeSpec.js | 17 ++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4286261b2186..aa25927e37a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,7 +14,7 @@ Change Log * Camera flights now disable collision with the terrain until all of the terrain in the area has finished loading. This prevents the camera from being moved to be above lower resolution terrain when flying to a position close to higher resolution terrain. [#4075](https://github.com/AnalyticalGraphicsInc/cesium/issues/4075) * Added support for Int32 and Uint32 in ComponentDatatypeSpec. * Added `GeocoderViewModel.keepExpanded` which when set to true will always keep the GeoCoder in its expanded state. - +* Added `ComponentDatatype.fromName` for getting a `ComponentDatatype` from its name. ### 1.24 - 2016-08-01 diff --git a/Source/Core/ComponentDatatype.js b/Source/Core/ComponentDatatype.js index 6b8b484dabde..46130f7569fa 100644 --- a/Source/Core/ComponentDatatype.js +++ b/Source/Core/ComponentDatatype.js @@ -297,5 +297,36 @@ define([ } }; + /** + * Get the ComponentDatatype from its name. + * + * @param {String} name The name of the ComponentDatatype. + * @returns {ComponentDatatype} The ComponentDatatype. + * + * @exception {DeveloperError} name is not a valid value. + */ + ComponentDatatype.fromName = function(name) { + switch (name) { + case 'BYTE': + return ComponentDatatype.BYTE; + case 'UNSIGNED_BYTE': + return ComponentDatatype.UNSIGNED_BYTE; + case 'SHORT': + return ComponentDatatype.SHORT; + case 'UNSIGNED_SHORT': + return ComponentDatatype.UNSIGNED_SHORT; + case 'INT': + return ComponentDatatype.INT; + case 'UNSIGNED_INT': + return ComponentDatatype.UNSIGNED_INT; + case 'FLOAT': + return ComponentDatatype.FLOAT; + case 'DOUBLE': + return ComponentDatatype.DOUBLE; + default: + throw new DeveloperError('name is not a valid value.'); + } + }; + return freezeObject(ComponentDatatype); }); diff --git a/Specs/Core/ComponentDatatypeSpec.js b/Specs/Core/ComponentDatatypeSpec.js index d646cc26bbc6..5d65b5e19e61 100644 --- a/Specs/Core/ComponentDatatypeSpec.js +++ b/Specs/Core/ComponentDatatypeSpec.js @@ -149,4 +149,21 @@ defineSuite([ ComponentDatatype.createTypedArray(ComponentDatatype.BYTE, undefined, 0, 1); }).toThrowDeveloperError(); }); + + it('fromName works', function() { + expect(ComponentDatatype.fromName('BYTE')).toEqual(ComponentDatatype.BYTE); + expect(ComponentDatatype.fromName('UNSIGNED_BYTE')).toEqual(ComponentDatatype.UNSIGNED_BYTE); + expect(ComponentDatatype.fromName('SHORT')).toEqual(ComponentDatatype.SHORT); + expect(ComponentDatatype.fromName('UNSIGNED_SHORT')).toEqual(ComponentDatatype.UNSIGNED_SHORT); + expect(ComponentDatatype.fromName('INT')).toEqual(ComponentDatatype.INT); + expect(ComponentDatatype.fromName('UNSIGNED_INT')).toEqual(ComponentDatatype.UNSIGNED_INT); + expect(ComponentDatatype.fromName('FLOAT')).toEqual(ComponentDatatype.FLOAT); + expect(ComponentDatatype.fromName('DOUBLE')).toEqual(ComponentDatatype.DOUBLE); + }); + + it('fromName throws without name', function() { + expect(function() { + ComponentDatatype.fromName(); + }).toThrowDeveloperError(); + }); }); From 6156c712d7dc8bf746f17b89936cc7a4a9655a43 Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Wed, 24 Aug 2016 10:18:37 -0400 Subject: [PATCH 2/2] Tweak reference doc --- Source/Core/ComponentDatatype.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/ComponentDatatype.js b/Source/Core/ComponentDatatype.js index 46130f7569fa..9d9d94ba08d2 100644 --- a/Source/Core/ComponentDatatype.js +++ b/Source/Core/ComponentDatatype.js @@ -151,7 +151,7 @@ define([ }; /** - * Gets the ComponentDatatype for the provided TypedArray instance. + * Gets the {@link ComponentDatatype} for the provided TypedArray instance. * * @param {TypedArray} array The typed array. * @returns {ComponentDatatype} The ComponentDatatype for the provided array, or undefined if the array is not a TypedArray.