LANDIS-II Archive Wiki
On-line archive of LANDIS-II project that was hosted at Google Code
Brought to you by:
jimm_domingo
An extension will have various source files. Many, if not all, the source files will need to access the model core. The core instance (object) is passed to an instance of the extension's PlugIn class. So how is this core instance made available to other classes in the extension?
A concise technique is to use a static class called "Model" defined in the Model.cs
file:
using Landis.Core;
namespace Landis.Extension.MyExtension
{
internal static class Model
{
internal static ICore Core;
}
}
The class' Core property is initialized by the PlugIn class in its LoadParameters method:
// PlugIn.cs
public override void LoadParameters(string dataFile,
ICore modelCore)
{
Model.Core = modelCore;
...
}
Other classes can then access the core with the Model.Core
property; for example:
// SiteVars.cs
using Landis.Core;
using Landis.SpatialModeling;
using Landis.Library.AgeOnlyCohorts;
namespace Landis.Extension.MyExtension
{
public static class SiteVars
{
private static ISiteVar<ISiteCohorts> cohorts;
private static ISiteVar<bool> disturbed;
//---------------------------------------------------------------------
public static void Initialize()
{
cohorts = Model.Core.GetSiteVar<ISiteCohorts>("Succession.AgeCohorts");
disturbed = Model.Core.Landscape.NewSiteVar<bool>();
}
//---------------------------------------------------------------------
public static ISiteVar<ISiteCohorts> Cohorts
{
get {
return cohorts;
}
}
//---------------------------------------------------------------------
public static ISiteVar<bool> Disturbed
{
get {
return disturbed;
}
}
}
}