/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" IDENT("@(#) UniMesg.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "UniMesg.h" struct unif_rec { UniMesIdCode::Value uni_offset; EventTypeCode::Value evn_offset; }; struct disp_rec { MesTypeCode::Value message_type; EventTypeCode::Value event_type; }; /* These are defined in UniMesg-conf.h * * struct unif_rec unif[MesTypeCode::size] = * struct disp_rec disp[UniMesIdCode::size] = */ #include "UniMesg-conf.h" /* UniMesId() is a function that takes two arguments: a MesTypeCode (M) * and an EventTypeCode (E). It returns the UniMesIdCode (U). * * f: M x E --> U * * The composite ZMtyp (Z) is M x E, thus there is a polymorphism: * * f: f(m, e) ; m in M and e in E * f: f(z) ; z in Z * * This function assumes that: * - The table for U lists message types in order of the table for M. * - The table for U keeps events for a message type together in the order * of the table for E. * - The table for E lists event types for a message type together in the * order of M. */ UniMesIdCode::Value UniMesId(MesTypeCode::Value mes_type, EventTypeCode::Value evn_type) { struct unif_rec ur = unif[(int)mes_type - (int)MesTypeCode::first]; if((ur.evn_offset != EventTypeCode::not_present) && (evn_type != EventTypeCode::not_present)) return (UniMesIdCode::Value) ((int)ur.uni_offset + (int)evn_type - (int)ur.evn_offset); else return ur.uni_offset; } UniMesIdCode::Value UniMesId(const ZMtyp &mid) { return UniMesId((MesTypeCode::Value)mid.getMesId(), mid.getEventType()); } /* The following functions are the inverse of UniMesId(): * * f': U --> M x E * * MesType(U) returns from M only, * EventType(U) returns from E only, * ZM(U) returns from M x E as an ZMtyp composite. */ MesTypeCode::Value MesType(UniMesIdCode::Value uni_mes) { struct disp_rec dr = disp[(int)uni_mes - (int)UniMesIdCode::first]; return dr.message_type; } EventTypeCode::Value EventType(UniMesIdCode::Value uni_mes) { struct disp_rec dr = disp[(int)uni_mes - (int)UniMesIdCode::first]; return dr.event_type; } ZMtyp ZM(UniMesIdCode::Value uni_mes) return r { r.setMesId(MesType(uni_mes)); r.setEventType(EventType(uni_mes)); }