Keywords: classdesc

Next: C++ model Objective-C design Up: Objective-C C++ interface Previous: Objective-C C++ interface Contents Index

## Introduction

Swarm is one of the better-known agent based modelling systems. Swarm consists of a simulation engine built in Objective-C [5,7,1,4,2] that takes a set of objects called a Swarm, and a schedule of actions to perform on them. Swarm defines interfaces that the objects need to adhere to (called protocols in Objective-C) in order for the simulation engine to interface to the Swarms. Finally, it provides a suite of visualisation tools or instruments that can be attached to running swarms to observe their behaviours. Swarm programs are hierarchical and the codes are object-oriented. The first beta version of Swarm was released in 1995 and was written in Objective-C. In 1999, a Java layer was introduced (release 2.0 onwards). A COM interface was proposed [3] which would allow objects written in arbitrary OO languages to be interfaced to swarm, but only partially implemented before funding ran out.

We take the view here that users may have implemented a model in C++, either because they like the features of that language, or for performance reasons, but desire to transplant the model into Swarm to take advantage of tools provided on that platform. The GNU CC compiler supports linking of C++, Obj C and plain C code into the same binary, however objects created in C++ and Objective cannot be shared between the two environments because of incompatible conventions about how objects are laid out in memory.

The strategy described here is for users to declare C++ a class, derived from a an object class that handles the implicit isa pointer in Objective C objects. Classdesc is used to create a program generator, that outputs an Objective C definition of the C++ object, and then we let Objective C's runtime system instantiate the object. The Objective C definition also includes wrapper methods that call the real C++ implemented methods of the object. Instance variables are available in both OO environments, although C++'s privacy declarations are ignored.

Next: C++ model Objective-C design Up: Objective-C C++ interface Previous: Objective-C C++ interface Contents Index