/* --------------------------------------------------------- *
* __________ D E L T A S C R I P T *
* (_________() *
* / === / - A fast, dynamic scripting language *
* | == | - Version 4.13.11.0 *
* / === / - Developed by Adam R. Nelson *
* | = = | - 2011-2013 *
* / === / - Distributed under GNU LGPL v3 *
* (________() - http://github.com/ar-nelson/deltascript *
* *
* --------------------------------------------------------- */
package com.sector91.delta.script.objects;
import java.util.Set;
import com.sector91.delta.script.DScriptErr;
import com.sector91.delta.script.Operator;
import com.sector91.delta.script.objects.reflect.DS_JavaClass;
/**
* <p>The "easy way" to turn an object into a {@link DS_Object}. This class
* overrides most of {@code DS_Object}'s required methods and includes built-in
* support for the {@link DS_JavaClass} class.</p>
*
* @author Adam R. Nelson
* @version 4.13.11.0
*/
public abstract class DS_AbstractObject implements DS_Object
{
public int compare(DS_Object o) throws DScriptErr
{throw DScriptErr.invalidCompare(this, o);}
public DS_Object dotGet(DS_Tag prop) throws DScriptErr
{return getDeltaScriptClass().instanceDotGet(this, prop);}
public void dotSet(DS_Tag prop, DS_Object value)
throws DScriptErr
{getDeltaScriptClass().instanceDotSet(this, prop, value);}
public Set<DS_Tag> getMembers()
{return getDeltaScriptClass().getInstanceMembers();}
public DS_Object operator(Operator op, DS_Object other)
throws DScriptErr
{throw DScriptErr.invalidOperation(op.str, this, other);}
public boolean booleanValue()
{return true;}
@Override public boolean equals(Object other)
{
if (other instanceof DS_Object)
return equals((DS_Object)other);
else
return false;
}
@Override public DS_Object clone() throws CloneNotSupportedException
{
throw new CloneNotSupportedException("Cannot clone an object of type " +
getTypeName() + ".");
}
public boolean is(DS_Object typeObj)
{
if (typeObj instanceof DS_JavaClass &&
((DS_JavaClass)typeObj).unbox().isAssignableFrom(getClass()))
return true;
return false;
}
@Override public String toString()
{return "(" + getTypeName() + "@" + System.identityHashCode(this) + ")";}
protected String standardToString(String description)
{return "(" + getTypeName() + ": " + description + ")";}
protected abstract DS_JavaClass getDeltaScriptClass();
}