Resolve/C++ Catalog
CT/Id_Name_Table/Kernel_2.h
Copyright © 2010, Reusable Software Research Group, The Ohio State University

//  /*-------------------------------------------------------------------*\
//  |   Concrete Template : Id_Name_Table_Kernel_2
//  \*-------------------------------------------------------------------*/

#ifndef CT_ID_NAME_TABLE_KERNEL_2
#define CT_ID_NAME_TABLE_KERNEL_2 1

///---------------------------------------------------------------------
/// Global Context -----------------------------------------------------
///---------------------------------------------------------------------

#include "AI/Id_Name_Table/Kernel.h"
#include "CT/Bijective_Partial_Map/Kernel_3a.h"
#include "CI/Text/Hash_1.h"
#include "CI/Integer/Hash_1.h"

///---------------------------------------------------------------------
/// Interface ----------------------------------------------------------
///---------------------------------------------------------------------

concrete_template <
        concrete_instance class Bijective_Partial_Map_Of_Integer_To_Text =
            Bijective_Partial_Map_Kernel_3a <
		    Integer,
                    Text,
                    139,
                    Integer_Hash_1,
                    Text_Hash_1
                >,			
	concrete_instance class Rep =
            Representation <Bijective_Partial_Map_Of_Integer_To_Text>
    >
class Id_Name_Table_Kernel_2 :
    implements
	abstract_instance Id_Name_Table_Kernel,
    encapsulates
	concrete_instance Rep
{
private:

    rep_field_name (Rep, 0, Bijective_Partial_Map_Of_Integer_To_Text,
		    id_name_pairs);

    /*!
	correspondence
	    self = self.id_name_pairs
    !*/

public:

    standard_concrete_operations (Id_Name_Table_Kernel_2);

    procedure_body Add_Id_Name_Pair (
	    preserves Integer id,
	    consumes Text& name
	)
    {
	object catalyst Integer id_copy = id;
	object Text name_copy;

	self[id_name_pairs].Define (id_copy, name);
    }

    procedure_body Remove_Id_Name_Pair (
	    preserves Integer id,
	    preserves Text name,
	    produces Integer& id_copy,
	    produces Text& name_copy
	)
    {
	self[id_name_pairs].D_Undefine (id, id_copy, name_copy);
    }
    
    procedure_body Remove_Any_Pair (
	    produces Integer& id,
	    produces Text& name
	)
    {
	self[id_name_pairs].Undefine_Any (id, name);
    }
    
    procedure_body Look_Up_Name_Via_Id (
	    preserves Integer id,
	    produces Text& name
	)
    {
	object catalyst Integer id_copy;
	object catalyst Text name_copy;
	
	self[id_name_pairs].D_Undefine (id, id_copy, name);
	name_copy = name;
	self[id_name_pairs].Define (id_copy, name_copy);
    }

    procedure_body Look_Up_Id_Via_Name (
	    produces Integer& id,
	    preserves Text name
	)
    {
	object catalyst Integer id_copy;
	object catalyst Text name_copy;
	
	self[id_name_pairs].R_Undefine (name, id, name_copy);
	id_copy = id;
	self[id_name_pairs].Define (id_copy, name_copy);
    }
    
    function_body Boolean Id_Is_In_Table (
	    preserves Integer id
	)
    {
	return self[id_name_pairs].D_Is_Defined (id);
    }

    function_body Boolean Name_Is_In_Table (
	    preserves Text name
	)
    {
	return self[id_name_pairs].R_Is_Defined (name);
    }
   
    function_body Integer Size ()
    {
	return self[id_name_pairs].Size ();
    }

};

#endif // CT_ID_NAME_TABLE_KERNEL_2

Last modified: Thu Jan 11 17:05:57 EST 2007