Thread: Custom Classes!
View Single Post
  #15  
Old 12-09-2007, 08:59 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Custom Classes (Database):
PHP Code:
function onCreated()
{
  
createClass"TObject" );
  
createClass"TMap"TObject );
  
createClass"TMapMod"TMap );
  
createClass"TNode"TObject );
}

function 
createClassclassNamesuperClass )
{
  if ( 
"class" in serverr.debug )
    echo(
"Creating class" SPC className );

  if ( (@ 
className ).type() == )
    (@ 
className ).destroy();

  
// Create class object
  
temp.newClass = new TStaticVar( (@className) );
  
temp.newClass.super superClass;

  
// Add Static Functions
  
temp.classes = { temp.newClass };
  if ( 
superClass != null )
    
temp.classes.addarraysuperClass.getClasses() );

  for ( 
temp.class: temp.classes )
    
temp.newClass.join( ("class_"temp.class.name @"_static").lower() );
  
temp.newClass.join"class_tclass" );
  
  
// Don't let the garabe collecter get this!
  
this.classes.addtemp.newClass );
  return 
temp.newClass;
}

public function 
getClasses()
{
  return 
this.classes;

class_tclass (Class):
PHP Code:
/** Class object **
(+) Class[] getClasses();
(+) Class getSuperclass();
(+) String getName();
(+) String toString();
(+) Object newInstance( objectName );
**/

public function getName()
{
  return 
this.name;
}

public function 
toString()
{
  return 
getName();
}

public function 
newInstanceparamobjectName )
{
  if ( 
objectName != "" )
    if ( (@ 
objectName ).type() == )
      (@ 
objectName ).destroy();

  
// Initialize Class
  
if ( "class" in serverr.debug )
    echo(
"Initializing class" SPC this.name );

  if ( 
objectName == "" )
    
temp.newInstance = new TStaticVar();
  else 
temp.newInstance = new TStaticVar( @objectName );
  
temp.newInstance.class = this;

  
temp.classes getClasses();
  for ( 
temp.class: temp.classes )
  {
    if ( 
"class" in serverr.debug )
      echo(
"Joining gClass" SPC temp.class.getName() );
    
temp.newInstance.join( ("class_"temp.class.getName() ).lower() );
  }

  
// Call constructor!
  
for ( temp.class: temp.classes )
  {
    if ( 
temp.class.getName() in temp.newInstance.getfunctions() )
    {
      
temp.newInstance.(@ temp.class.getName() )( param );
      break;
    }
  }


  return 
temp.newInstance;
}

public function 
getClasses()
{
  
temp.classes = {this};

  
temp.super getSuperclass();
  if ( 
temp.super != null )
    
temp.classes.addarraytemp.super.getClasses() );

  return 
temp.classes;
}

public function 
getSuperclass()
{
  return 
this.super;

class_tobject (Class):
PHP Code:
/** General Object **
(+) void TObject();

(+) boolean instanceOf( Class class );
(+) String toString();
(+) Class getClass();
**/

public function TObject()
{
  if ( 
"class" in serverr.debug )
    echo( 
"Initialized Object" SPC toString() );
}

public function instanceOf( class )
{
  return ( class 
in getClass().getClasses() );
}

public function 
toString()
{
  return 
this.name @"-"this.class.getName();
}

public function 
getClass()
{
  return 
this.class;

And... As a bonus class to this great deal, TMap! (Call now, and get TNode for free!) Only fifty-five payments of 9.99$:
PHP Code:
/** TMap inherits TObject **
// Constructor
(+) void TMap( String[][] contents );

// Object Manipulation
(+) Object get( String key );
(+) void put( String key, Object value );
(+) void putAll( String[][] contents );
(+) void removeKey( String key ); * can't override .remove
(+) void clearMap();

// Testing
(+) boolean containsKey( String key );
(+) boolean containsValue( Object value );

(+) String[] keySet();
(+) Object[] values();

(+) int mapSize();
(+) boolean isEmpty();

(+) String[][] toArray();
**/

public function TMapinitialContents )
{
  
TObject();
  if ( 
this.init )
    return;

  
this.init true;
  
putAllinitialContents );
}

public function 
putAllnewContents )
{
  for ( 
temp.contentnewContents )
    
this.puttemp.content[0], temp.content[1] );
}

public function 
getkey )
{
  for ( 
temp.contentthis.contents )
  {
    if ( 
temp.content[0] == key )
      return 
temp.content[1];
  }

  return 
null;
}

public function 
putkeyvalue )
{
  for ( 
temp.contentthis.contents )
  {
    if ( 
temp.content[0] == key )
    {
      
temp.content[1] = value;
      return;
    }
  }

  
this.contents.add( {keyvalue} );
  return;
}

public function 
removeKeykey )
{
  for ( 
temp.0temp.this.contents.size(); temp.++ )
  {
    
temp.content this.contentstemp.];
    if ( 
temp.content[0] == key )
    {
      
this.contents.deletetemp.);
      return;
    }
  }
}

public function 
clearMap()
{
  
this.contents "";
}

public function 
mapSize()
{
  return 
this.contents.size();
}

public function 
isEmpty()
{
  return (
this.size() == 0);
}

public function 
containsKeykey )
{
  for ( 
temp.contentthis.contents )
    if ( 
temp.content[0] == key )
      return 
true;
  return 
false;
}

public function 
containsValuevalue )
{
  for ( 
temp.contentthis.contents )
    if ( 
temp.content[1] == value )
      return 
true;
  return 
false;
}

public function 
values()
{
  
temp.values = new[0];
  for ( 
temp.contentthis.contents )
    
temp.values.addtemp.content[1] );
  return 
temp.values;
}

public function 
keySet()
{
  
temp.keys = new[0];
  for ( 
temp.contentthis.contents )
    
temp.keys.addtemp.content[0] );
  return 
temp.keys;
}

public function 
toArray()
{
  return 
this.contents;

Reply With Quote