1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
FALCON - The Falcon Programming Language.
FILE: deptab.cpp
Dependency table support for modules.
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: dom ago 21 2005
-------------------------------------------------------------------
(C) Copyright 2004: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
/** \file
Dependency table support for modules.
*/
#include <falcon/string.h>
#include <falcon/stream.h>
#include <falcon/deptab.h>
#include <falcon/common.h>
#include <falcon/module.h>
namespace Falcon {
DependTable::DependTable():
Map( &traits::t_stringptr_own(), &traits::t_voidp() )
{
}
DependTable::~DependTable()
{
MapIterator iter = begin();
while( iter.hasCurrent() ) {
delete *(ModuleDepData **) iter.currentValue();
iter.next();
}
}
bool DependTable::save( Stream *out ) const
{
uint32 s = endianInt32(size());
out->write( &s, sizeof( s ) );
MapIterator iter = begin();
while( iter.hasCurrent() ) {
const String *name = *(const String **) iter.currentKey();
const ModuleDepData *data = *(const ModuleDepData **) iter.currentValue();
name->serialize( out );
data->moduleName().serialize( out );
s = endianInt32( data->isPrivate() ? 1 : 0 );
out->write( &s, sizeof( s ) );
s = endianInt32( data->isFile() ? 1 : 0 );
out->write( &s, sizeof( s ) );
iter.next();
}
return true;
}
bool DependTable::load( Module *mod, Stream *in )
{
uint32 s;
in->read( &s, sizeof( s ) );
s = endianInt32( s );
while( s > 0 )
{
uint32 id;
String alias, modname;
if ( ! alias.deserialize( in, false )
|| ! modname.deserialize( in, false ) )
{
return false;
}
in->read( &id, sizeof( id ) );
bool isPrivate = endianInt32(id) != 0;
in->read( &id, sizeof( id ) );
bool isFile = endianInt32(id) != 0;
insert( new String(alias), new ModuleDepData( modname, isPrivate, isFile ) );
--s;
}
return true;
}
void DependTable::addDependency( const String &alias, const String& name, bool bPrivate, bool bFile )
{
insert( new String(alias), new ModuleDepData( name, bPrivate, bFile ) );
}
}
/* end of deptab.cpp */
|