Files
cappuccino/Objective-J/CFDictionary.js
T
Martin Carlberg 6094d25cfb New: Support to compile deep structured project in the web browser
A Cappuccino project has always needed to have a flat file structure to
be able to compile from source in the web browser.

A new dictionary can be added to the project's Info.plist with the key
'CPFileTranslationDictionary'. It should contain all the path
translations in the project to allow the Browser to find out where in
the file structure the source files are. Check in the AppKit framework
for an example.

Also, a include list can be added in the Info.plist for the key
'CPCompileIncludeFileArray'. The file in the list will be included
by a '#include' statement for each file that is compiled in this project

A last new feature is to add macros in the 'OBJJ_COMPILER_FLAGS' global
variable. It is usually declared in the index.html file. It is done
with the format '-Dmacroname[=macrodefinition]'.

An updated Info.plist file in the AppKit framework will allow the AppKit
to compile from the source in the web browser. The following things is
needed to get this to work:

1. Replace the AppKit folder in your project's Frameworks folder with a
copy of the AppKit folder from the Cappuccino project.
2. Add a copy of the built Aristo2.blend folder to the AppKit's Resource
folder.
3. Add "-DPLATFORM_DOM", "-DPLATFORM_BROWSER" and optionally "-DDEBUG"
to the global variable 'OBJJ_COMPILER_FLAGS' in the project's index.html
file.

The app load time will increase (about 3 seconds on a 2018 MacBook Pro)
as the AppKit framework is compiled from source.

The Foundation framework is not yet tested but it might be working by
adding info about the file structure in the Info.plist file.
2020-12-21 11:14:36 +01:00

262 lines
5.9 KiB
JavaScript

/*
* CFDictionary.js
* Objective-J
*
* Created by Francisco Tolmasky.
* Copyright 2008-2010, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
GLOBAL(CFDictionary) = function(/*CFDictionary*/ aDictionary)
{
this._keys = [];
this._count = 0;
this._buckets = { };
this._UID = objj_generateObjectUID();
}
var indexOf = Array.prototype.indexOf,
hasOwnProperty = Object.prototype.hasOwnProperty;
CFDictionary.prototype.copy = function()
{
// Immutable, so no need to actually copy.
return this;
};
CFDictionary.prototype.mutableCopy = function()
{
var newDictionary = new CFMutableDictionary(),
keys = this._keys,
count = this._count;
newDictionary._keys = keys.slice();
newDictionary._count = count;
var index = 0,
buckets = this._buckets,
newBuckets = newDictionary._buckets;
for (; index < count; ++index)
{
var key = keys[index];
newBuckets[key] = buckets[key];
}
return newDictionary;
};
CFDictionary.prototype.containsKey = function(/*String*/ aKey)
{
return hasOwnProperty.apply(this._buckets, [aKey]);
};
DISPLAY_NAME(CFDictionary.prototype.containsKey);
CFDictionary.prototype.containsValue = function(/*id*/ anObject)
{
var keys = this._keys,
buckets = this._buckets,
index = 0,
count = keys.length;
for (; index < count; ++index)
if (buckets[keys[index]] === anObject)
return YES;
return NO;
};
DISPLAY_NAME(CFDictionary.prototype.containsValue);
CFDictionary.prototype.count = function()
{
return this._count;
};
DISPLAY_NAME(CFDictionary.prototype.count);
CFDictionary.prototype.countOfKey = function(/*String*/ aKey)
{
return this.containsKey(aKey) ? 1 : 0;
};
DISPLAY_NAME(CFDictionary.prototype.countOfKey);
CFDictionary.prototype.countOfValue = function(/*id*/ anObject)
{
var keys = this._keys,
buckets = this._buckets,
index = 0,
count = keys.length,
countOfValue = 0;
for (; index < count; ++index)
if (buckets[keys[index]] === anObject)
++countOfValue;
return countOfValue;
};
DISPLAY_NAME(CFDictionary.prototype.countOfValue);
CFDictionary.prototype.keys = function()
{
return this._keys.slice();
};
DISPLAY_NAME(CFDictionary.prototype.keys);
CFDictionary.prototype.valueForKey = function(/*String*/ aKey)
{
var buckets = this._buckets;
if (!hasOwnProperty.apply(buckets, [aKey]))
return nil;
return buckets[aKey];
};
DISPLAY_NAME(CFDictionary.prototype.valueForKey);
CFDictionary.prototype.toString = function()
{
var string = "{\n",
keys = this._keys,
index = 0,
count = this._count;
for (; index < count; ++index)
{
var key = keys[index];
string += "\t" + key + " = \"" + String(this.valueForKey(key)).split('\n').join("\n\t") + "\"\n";
}
return string + "}";
};
DISPLAY_NAME(CFDictionary.prototype.toString);
CFDictionary.prototype.toJSObject = function()
{
var jsObject = new Object(),
keys = this._keys,
index = 0,
count = this._count;
for (; index < count; ++index)
{
var key = keys[index];
jsObject[key] = this.valueForKey(key);
}
return jsObject;
};
DISPLAY_NAME(CFDictionary.prototype.toJSObject);
GLOBAL(CFMutableDictionary) = function(/*CFDictionary*/ aDictionary)
{
CFDictionary.apply(this, []);
}
CFMutableDictionary.prototype = new CFDictionary();
CFMutableDictionary.prototype.copy = function()
{
return this.mutableCopy();
};
CFMutableDictionary.prototype.addValueForKey = function(/*String*/ aKey, /*Object*/ aValue)
{
if (this.containsKey(aKey))
return;
++this._count;
this._keys.push(aKey);
this._buckets[aKey] = aValue;
};
DISPLAY_NAME(CFMutableDictionary.prototype.addValueForKey);
CFMutableDictionary.prototype.removeValueForKey = function(/*String*/ aKey)
{
var indexOfKey = -1;
if (indexOf)
indexOfKey = indexOf.call(this._keys, aKey);
else
{
var keys = this._keys,
index = 0,
count = keys.length;
for (; index < count; ++index)
if (keys[index] === aKey)
{
indexOfKey = index;
break;
}
}
if (indexOfKey === -1)
return;
--this._count;
this._keys.splice(indexOfKey, 1);
delete this._buckets[aKey];
};
DISPLAY_NAME(CFMutableDictionary.prototype.removeValueForKey);
CFMutableDictionary.prototype.removeAllValues = function()
{
this._count = 0;
this._keys = [];
this._buckets = { };
};
DISPLAY_NAME(CFMutableDictionary.prototype.removeAllValues);
CFMutableDictionary.prototype.replaceValueForKey = function(/*String*/ aKey, /*Object*/ aValue)
{
if (!this.containsKey(aKey))
return;
this._buckets[aKey] = aValue;
};
DISPLAY_NAME(CFMutableDictionary.prototype.replaceValueForKey);
CFMutableDictionary.prototype.setValueForKey = function(/*String*/ aKey, /*Object*/ aValue)
{
if (aValue == nil)
this.removeValueForKey(aKey);
else if (this.containsKey(aKey))
this.replaceValueForKey(aKey, aValue);
else
this.addValueForKey(aKey, aValue);
};
DISPLAY_NAME(CFMutableDictionary.prototype.setValueForKey);