Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ComponentDatatype.fromName #4230

Merged
merged 2 commits into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});