(function() {

  this.def_class('Rome',DObject,function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function Rome(){}; this.__ctor__.prototype = this.prototype; }

    this.def_class('Bitmap',__scope.Struct,function(__scope,__class){

      this.__ctor__ = function Bitmap(doc, key, options) {
        this["@doc"] = doc;
        this["@key"] = key;
        this["@options"] = options;
        this["@changes"] = [];
        return this;
      }; this.__ctor__.prototype = this.prototype;;

      this.prototype.load = function(raw) {
        if (!this["@array"]) this["@array"] = (raw && raw.data || "").split("");
        this["ready!"]();
        return this;
      }; __method_added(this,"load");

      this.prototype.getrange = function(offset, length) {
        return this["@array"].slice(offset, offset + length);
      }; __method_added(this,"getrange");

      this.prototype.setrange = function(offset, value) {
        var i, val, _len, _primitive;
        if (typeof value === 'string') {
          if (value.length() === 1) {
            this['[]='](offset,value);
            return;
          }
          value = value.split("");
        }
        for (i = 0, _len = (value.len ? value.len() : value.length),_primitive = (value instanceof Array || !value.at); i < _len; i++) {
          val = _primitive ? value[i] : value.at(i);
          this['[]='](offset + i,val);
        }
        return this;
      }; __method_added(this,"setrange");

      this.prototype["[]"] = function(index) {
        return this["@array"][index];
      }; __method_added(this,"[]");

      this.prototype["[]="] = function(index, value) {
        if (index < 0) return this;
        if (value !== this["@array"][index]) {
          this["@array"][index] = value;
          this["@changes"].push(index, value);
          this["@doc"]["@dirty"].sadd(this["@key"]);
          this.emit('change', index, value);
        }
        return this;
      }; __method_added(this,"[]=");

      this.prototype.each = function(block) {
        return this["@array"].forEach(block);
      }; __method_added(this,"each");

      this.prototype.size = function() {
        return this["@array"]['length'];
      }; __method_added(this,"size");

      this.prototype.raw = function() {
        return this["@array"];
      }; __method_added(this,"raw");

      this.prototype.flush = function() {
        var changes;
        changes = this["@changes"];
        this["@changes"] = [];
        return changes;
      }; __method_added(this,"flush");

    });

  });

}).call($$base);

