#
# Functions for data structures.
#

use warnings;
use strict;

require "symboliser-functions.pl";


# Add the map information to the global variable

sub add_mapinfo
  {
   my($global,%mapinfo)=(@_);

   my($key);

   foreach $key (keys %mapinfo)
     {
      $global->{mapinfo}{$key}=$mapinfo{$key};
     }
  }

# Add the datasource to the global variable

sub add_datasource
  {
   my($global,$type,%parameters)=(@_);

   $global->{datasources}{$type}{type}=$type;

   my($key);

   foreach $key (keys %parameters)
     {
      $global->{datasources}{$type}{$key}=$parameters{$key};
     }
  }

# Add the parameters to the global variable

sub add_parameters
  {
   my($global,%parameters)=(@_);

   my($key);

   foreach $key (keys %parameters)
     {
      $global->{parameters}{$key}=$parameters{$key};
     }
  }

# Add the fontsets to the global variable

sub add_fontset
  {
   my($global,$name,@fonts)=(@_);

   push(@{$global->{fontsets}},{name=>$name,fonts=>[@fonts]});
  }

# Add the filesource to the global variable

sub add_filesource
  {
   my($global,$name,$dir)=(@_);

   push(@{$global->{filesources}},{name=>$name,dir=>$dir});
  }

# Add a rule to a style

sub add_rule
  {
   my($global,%parameters)=(@_);

   push(@{$global->{rules}},{%parameters});

   push(@{$global->{styles}[$global->{'current-style'}]{rules}},$#{$global->{rules}});
  }

# Add a style

sub add_style
  {
   my($global,%parameters)=(@_);

   if(defined $global->{'style-index'}{$parameters{name}})
     {
      $global->{'current-style'}=$global->{'style-index'}{$parameters{name}};
     }
   else
     {
      push(@{$global->{styles}},{%parameters,rules=>[]});

      $global->{'current-style'}=$#{$global->{styles}};

      $global->{'style-index'}{$parameters{name}}=$global->{'current-style'};

      push(@{$global->{layers}[$global->{'current-layer'}]{styles}},$#{$global->{styles}});
     }
  }

# Add a layer

sub add_layer
  {
   my($global,%parameters)=(@_);

   if(defined $global->{'layer-index'}{$parameters{name}})
     {
      $global->{'current-layer'}=$global->{'layer-index'}{$parameters{name}};
     }
   else
     {
      push(@{$global->{layers}},{%parameters,styles=>[]});

      $global->{'current-layer'}=$#{$global->{layers}};

      $global->{'layer-index'}{$parameters{name}}=$global->{'current-layer'};
     }
  }


#
1;
