Skip to content

Commit

Permalink
Merge pull request #4230 from AnalyticalGraphicsInc/component-datatyp…
Browse files Browse the repository at this point in the history
…e-update

Added ComponentDatatype.fromName
  • Loading branch information
pjcozzi authored Aug 24, 2016
2 parents 0104356 + 6156c71 commit f2b4bed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 32 additions & 1 deletion Source/Core/ComponentDatatype.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
});
17 changes: 17 additions & 0 deletions Specs/Core/ComponentDatatypeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit f2b4bed

Please sign in to comment.