Source: WKcEnum.js

/*jslint es5: true, plusplus: true, white: true, indent: 2, maxlen: 90 */
/*global $wk$ */
/**
 *  @author    Wolfgang Kowarschick
 *  @copyright 2012-2013, Wolfgang Kowarschick
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted under the terms of the 
 *  Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported    
 *  (CC BY-NC-SA 3.0: http://creativecommons.org/licenses/by-nc-sa/3.0/). 
 */

 
////////////////////////////////////////////////////////////////////////////////
// Class "$wk$.vclsd.service.WKcService"
////////////////////////////////////////////////////////////////////////////////

$wk$(
function($)
{ "use strict";

  var $new$         = $.$new$,
      i, n,
      l_uid         = -2,
      l_class_props = ["classFullName", "classID", "classPath"],
      l_class_prop_values,
      l_prototype;
  
  /** 
   *  <code>$wk$.WKcEnum</code> is a constructor to create enumeration types.
   *  <p>
   *  Each argument passed to the constructor describes a enumeration 
   *  key/value pair. Three types of arguments are supported:
   *  <dl>
   *  <dt><code>String</code>
   *  <dd>The string denotes the enumaration key. As enumaration value
   *      a unique integer number is used.
   *  </dd>
   *  <dt><code>Array</code>
   *  <dd>The array must contain two values: The first value, a string, 
   *      denotes the key, the second value is used as enumeration value.
   *  </dd>
   *  <dt><code>Object</code>
   *  <dd>The object itself is used a enumartion value. It must contain a 
   *      property named <code>key</code>, the value of which is used as
   *      enumeration key.
   *  </dd>          
   *  </dl>
   *  </p>
   * 
   *  @class
   *  @name $wk$.WKcEnum 
   *  @param arguments  A list of enumeration key/value specifiers.  
   *  @returns {Object} A new enumeration object.
   */
  function WKcEnum()
  { if (!(this instanceof WKcEnum))
    { return $new$(WKcEnum, arguments); }
     
    var i,
        l_length,
        l_arg,
        l_key;
   
    for (i = 0, l_length = arguments.length; i < l_length; i++)
    { l_arg = arguments[i];
    
      if (l_arg.constructor === String)
      { l_key = l_arg;
        l_uid--;
        this[l_arg] = l_uid--; 
      }
      else if (l_arg instanceof Array)
      { l_key       = l_arg[0];
        this[l_key] = l_arg[1]; 
      }
      else 
      { l_key = l_arg.key;
        if (l_arg instanceof Object)
        { this[l_key] = l_arg; }
        else
        { throw new Error
                (l_arg + 
                 " is neither a string nor an array nor an enumeration object."
                ); 
        }
      }
      Object.defineProperty(this, l_key, 
                            { writable : false, configurable: false }
                           );
    }
  }
    
  l_prototype             = WKcEnum.prototype;
  l_prototype.constructor = WKcEnum;
  l_class_prop_values    = ["$wk$.WKcEnum", "WKcEnum", "$wk$"];

  WKcEnum.fullName = l_class_prop_values[0];
  WKcEnum.id       = l_class_prop_values[1];
  WKcEnum.path     = l_class_prop_values[2];
  
  for (i=0, n=l_class_props.length; i < n; i++)
  { Object.defineProperty(l_prototype,
                          l_class_props[i],
                          { configurable: false,
                            enumerable:   false,
                            value:        l_class_prop_values[i],
                            writable:     false
                          }
                         );
  }

  $.moduleAdd({ name:   "$wk$.WKcEnum",
                module: { WKcEnum: WKcEnum }
             });
});

////////////////////////////////////////////////////////////////////////////////
// End of Class "$wk$.ldvcs.service.WKcService"
////////////////////////////////////////////////////////////////////////////////
W. Kowarschick © 2013 (CC BY-NC-SA 3.0: http://creativecommons.org/licenses/by-nc-sa/3.0/)
Documentation generated by JSDoc 3.3.0-dev on Sat Oct 05 2013 15:14:39 GMT+0200 (MESZ) using the DocStrap template.