found in the LICENSE file.
-->
-<link rel="import" href="/tvcm/guid.html">
+<link rel="import" href="/base/guid.html">
<script>
'use strict';
/**
* @fileoverview Provides the Event class.
*/
-tvcm.exportTo('tracing.trace_model', function() {
+tv.exportTo('tracing.trace_model', function() {
/**
* The SelectionState enum defines how Events are displayed in the view.
DIMMED: 3
};
+ // Cached values for getCategoryParts.
+ var categoryPartsFor = {};
+
+ /**
+ * Categories are stored in comma-separated form, e.g: 'a,b' meaning
+ * that the event is part of the a and b category.
+ *
+ * This function returns the category split by string, caching the
+ * array for performance.
+ *
+ * Do not mutate the returned array!!!!
+ */
+ function getCategoryParts(category) {
+ var parts = categoryPartsFor[category];
+ if (parts !== undefined)
+ return parts;
+ parts = category.split(',');
+ categoryPartsFor[category] = parts;
+ return parts;
+ }
+
/**
* An Event is the base type for any non-container, selectable piece
* of data in the trace model.
* @constructor
*/
function Event() {
- this.guid_ = tvcm.GUID.allocate();
+ this.guid_ = tv.GUID.allocate();
this.selectionState = SelectionState.NONE;
}
}
};
+ Event.decorateSubtype = function(baseConstructor) {
+ if (baseConstructor.register !== undefined ||
+ baseConstructor.unregister !== undefined ||
+ baseConstructor.getConstructor !== undefined) {
+ throw new Error('Already decorated: ' + baseConstructor);
+ }
+
+ baseConstructor.categoryToConstructorMap_ = {};
+ baseConstructor.nameToConstructorMap_ = {};
+
+ baseConstructor.register = function(name, constructor) {
+ if (baseConstructor.nameToConstructorMap_[name])
+ throw new Error('Constructor already registered for ' + name);
+ baseConstructor.nameToConstructorMap_[name] = constructor;
+ };
+
+ baseConstructor.unregister = function(name) {
+ delete baseConstructor.nameToConstructorMap_[name];
+ };
+
+ baseConstructor.registerCategory = function(category, constructor) {
+ if (baseConstructor.categoryToConstructorMap_[category])
+ throw new Error('Constructor already registered for ' + category);
+ baseConstructor.categoryToConstructorMap_[category] = constructor;
+ };
+ baseConstructor.unregisterCategory = function(category, constructor) {
+ delete baseConstructor.categoryToConstructorMap_[category];
+ };
+
+ baseConstructor.getConstructor = function(category, name) {
+ var categoryParts = getCategoryParts(category);
+ for (var i = 0; i < categoryParts.length; i++) {
+ var categoryPart = categoryParts[i];
+ if (baseConstructor.categoryToConstructorMap_[categoryPart])
+ return baseConstructor.categoryToConstructorMap_[categoryPart];
+ }
+ if (baseConstructor.nameToConstructorMap_[name])
+ return baseConstructor.nameToConstructorMap_[name];
+ return baseConstructor;
+ };
+ };
+
return {
Event: Event,
SelectionState: SelectionState