📄 swarm.objectbase.sgml.reference.html
字号:
<HTML><HEAD><TITLE>Objectbase Library</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.53"><LINKREL="HOME"TITLE="Documentation Set for Swarm 2.1.1"HREF="set.html"><LINKREL="UP"TITLE="Reference Guide for Swarm 2.1.1"HREF="book930.html"><LINKREL="PREVIOUS"TITLE="General"HREF="swarm.activity.generic.module.html"><LINKREL="NEXT"TITLE="ActivityControl"HREF="swarm.objectbase.activitycontrol.protocol.html"></HEAD><BODYCLASS="REFERENCE"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Documentation Set for Swarm 2.1.1</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="swarm.activity.generic.module.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="swarm.objectbase.activitycontrol.protocol.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="REFERENCE"><ANAME="SWARM.OBJECTBASE.SGML.REFERENCE"></A><DIVCLASS="TITLEPAGE"><H1CLASS="TITLE">IV. Objectbase Library</H1><DIVCLASS="PARTINTRO"><ANAME="AEN11230"></A><TABLECLASS="SIDEBAR"BORDER="1"CELLPADDING="5"><TR><TD><DIVCLASS="SIDEBAR"><P><B>Overview</B></P><P>The <ICLASS="EMPHASIS">objectbase</I> library encapsulates various fundamental aspects of the <ICLASS="EMPHASIS">Swarm</I> object model and defines the probing machinery used to take data from <ICLASS="EMPHASIS">Swarm</I> objects. Most of the underlying functionality of the classes defined here is contained in the <ICLASS="EMPHASIS"><AHREF="swarm.defobj.sgml.reference.html">defobj</A></I> and <ICLASS="EMPHASIS"><AHREF="swarm.activity.sgml.reference.html">activity</A></I> libraries. </P><DIVCLASS="FORMALPARA"><P><B>Probes. </B>Probes are idealized entities that are intended to allow the user to monitor and modify the innards of objects without explicitly providing the functionality to do so at compile time. Hence, they allow dynamic interaction with an objects instance variables and methods. Most of the functionality of probes is implemented here; but, at present, they are intimately linked to the <ICLASS="EMPHASIS"><AHREF="swarm.simtoolsgui.sgml.reference.html">simtools</A></I> library, which contains all the widgetry needed to use probes from a GUI. Despite this intimacy, probes are intended to be a general purpose mechanism for <ICLASS="EMPHASIS">any</I> agent or device to interact dynamically with <ICLASS="EMPHASIS">Swarm</I> objects. The Probes section in the <AHREF="http://www.swarm.org"TARGET="_top"><ICLASS="CITETITLE">Swarm User Guide</I></A> will explain more about the reasoning and purpose behind probes. </P></DIV></DIV></TD></TR></TABLE><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SWARM.OBJECTBASE.SGML.SECT1.DEPEND">1. Dependencies</A></H1><P>Following are the other header files imported by <objectbase.h>:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">#import <defobj.h>#import <activity.h></PRE></TD></TR></TABLE> The <ICLASS="EMPHASIS">defobj</I> library interface is included to provide the basic object support. </P></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SWARM.OBJECTBASE.SGML.SECT1.COMPAT">2. Compatibility</A></H1><P></P><UL><LI><DIVCLASS="FORMALPARA"><P><B>1.0.4 => 1.0.5. </B>No changes.</P></DIV></LI><LI><DIVCLASS="FORMALPARA"><P><B>1.0.3 => 1.0.4. </B>The name of this library is now <ICLASS="EMPHASIS"><TTCLASS="LITERAL">objectbase</TT></I>, it is has been renamed from <ICLASS="EMPHASIS"><TTCLASS="LITERAL">swarmobject</TT></I> largely to reflect the more generic nature of the library and also motivated by the impending port of Swarm to Windows NT (to avoid filename conflicts with the <TTCLASS="LITERAL">SwarmObject</TT> class). There should be little, or no effect on the user, the only visible change is the fact that the actual library (.a) or (.so) file will now have a different name and the header file name has changed. A symbolic link from <TTCLASS="LITERAL">objectbase.h</TT> to <TTCLASS="LITERAL">swarmobject.h</TT> has been provided in the distribution, to ensure backwards compatibility, however, users should <ICLASS="EMPHASIS">not</I> continue to rely on this being so. Users should port references to <TTCLASS="LITERAL">swarmobject.h</TT> in their code to <TTCLASS="LITERAL">objectbase.h</TT>, because this symlink will be removed in a future release.</P></DIV><P><ICLASS="EMPHASIS"><ICLASS="EMPHASIS">Note</I>: this is no way affects the</I> <TTCLASS="LITERAL">SwarmObject</TT> class which remains the same as in all previous releases.</P></LI><LI><DIVCLASS="FORMALPARA"><P><B>1.0.0 => 1.0.1. </B>The interface has changed again! <ICLASS="EMPHASIS">EmptyProbeMap</I> is now a subclass of <ICLASS="EMPHASIS">CustomProbeMap</I>, which is subclassed from <ICLASS="EMPHASIS">ProbeMap</I>. And a shortcut <TTCLASS="LITERAL">create:</TT> method was added to that branch.</P></DIV><P>Also, a new method was added to <ICLASS="EMPHASIS">ProbeLibrary</I> called <TTCLASS="LITERAL">isProbeMapDefinedFor</TT> that serves to non-invasively test for the existence of a <ICLASS="EMPHASIS">ProbeMap</I> for a given class.</P></LI><LI><DIVCLASS="FORMALPARA"><P><B><ICLASS="EMPHASIS">Beta</I> => 1.0.0. </B>The new interface for the <ICLASS="EMPHASIS">swarmobject</I> library might cause some problems for apps that worked under the Beta release of Swarm. To get the whole scoop, read the <AHREF="swarm.library.sgml.appendix.html">Library Interface Conventions</A>. </P></DIV></LI></UL></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SWARM.OBJECTBASE.SGML.SECT1.USAGE">3. Usage Guide</A></H1><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN11301">3.1. Overview</A></H2><P>The <ICLASS="EMPHASIS">objectbase</I> library contains the most basic objects users need to design their agents and swarms. It also serves, at present, as a repository for the probe machinery, which is provided for every <ICLASS="EMPHASIS">SwarmObject</I>. The way the classes in this library are to be used is varied. But, basically, it is provided so that the user will have something to subclass from for her own objects and Swarms. </P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN11306">3.2. Example Usage of <ICLASS="EMPHASIS">SwarmObject</I></A></H2><P>The best way to explain how the library should be used is to walk through an example. So, using Heatbugs, we'll walk through the ways <ICLASS="EMPHASIS">objectbase</I> is used and discuss them. Since more documentation is usually better than less, I'm going to explain things at a low level so that those not familiar with Objective C will understand the discussion. If you already are familiar with Objective C, then you should skip this part. </P><P>First off, the basic elements of the Heatbugs simulation are the heatbugs, the model swarm (which bundles the heatbugs), and the observer swarm (which bundles the displays of the probes poking into the model swarm and the heatbugs). The interface files for each show what must be imported and the declaration syntax needed to subclass from <ICLASS="EMPHASIS">SwarmObject</I>. </P><P>We'll use <TTCLASS="LITERAL">Heatbug.h</TT> for our discussion here. The first part of the file shows the C-preprocessor imports needed:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">#import <objectbase/SwarmObject.h>#import <space.h> #import "HeatSpace.h" #import <tkobjc/Raster.h> </PRE></TD></TR></TABLE> </P><P>The <TTCLASS="LITERAL">#import <objectbase/SwarmObject.h>;</TT> is included in order to subclass from <ICLASS="EMPHASIS">SwarmObject</I>. However, to provide backwards compatibility, we've placed this import in the library interface file <TTCLASS="LITERAL">objectbase.h</TT> as well, which means one could subclass from <ICLASS="EMPHASIS">SwarmObject</I> by simply importing the <TTCLASS="LITERAL">objectbase.h</TT> file. This is discouraged in order to make the library interfaces as standard as possible. </P><P>The next <ICLASS="EMPHASIS">objectbase</I> relevant piece of code in this file is:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">@interface Heatbug: SwarmObject{ double unhappiness; int x, y; HeatValue idealTemperature; HeatValue outputHeat; float randomMoveProbability; Grid2d * world; int worldXSize, worldYSize; HeatSpace * heat; Color bugColor; }</PRE></TD></TR></TABLE> </P><P>The <TTCLASS="LITERAL">@interface</TT> keyword indicates that you are beginning the definition of the part of an object (a <ICLASS="EMPHASIS">Heatbug</I> in this case) that will be visible to other objects. The <TTCLASS="LITERAL">Heatbug: SwarmObject</TT> indicates that you are calling this object <ICLASS="EMPHASIS">Heatbug</I> and it is a subclass of <ICLASS="EMPHASIS">SwarmObject</I>. What follows between the curly braces ({}) are the instance variables defined for the <ICLASS="EMPHASIS">Heatbug</I> class <ICLASS="EMPHASIS">above and beyond</I> those inherited from the <ICLASS="EMPHASIS">SwarmObject</I> class. </P><P>Inside this "agent," we have defined several parameters associated with either the agent, itself, or the space in which it sits. Any data that will need to be present throughout all the behavior and lifetime of the agent should be declared here. Also, anything declared here will be accessible to the probe machinery, and so will be capable of being manipulated and viewed from outside the agent. </P><P
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -