/*
   b_mode_t.cpp   Generated by the Ballista(tm) Project data object compiler
   Copyright (C) 1998-2001  Carnegie Mellon University

   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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

   File generated Tuesday, May 22 at 05:04 PM EDT

TITLE
   b_mode_t.cpp
*/

//--------------------------------------------------------------------

#include <errno.h>
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <stream.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "b_mode_t.h"

//--------------------------------------------------------------------


//--------------------------------------------------------------------

CLASSNAME::CLASSNAME()
{
  //DIAL DECLARATIONS HERE

  //generated

   strcpy(_b_mode_tTYPENAME,CLASS_STRING);
strcpy(_b_mode_tU_READ,"b_mode_t_U_READ");
strcpy(_b_mode_tU_WRITE,"b_mode_t_U_WRITE");
strcpy(_b_mode_tU_EXEC,"b_mode_t_U_EXEC");
strcpy(_b_mode_tU_RWX,"b_mode_t_U_RWX");
strcpy(_b_mode_tU_NONE,"b_mode_t_U_NONE");
strcpy(_b_mode_tG_READ,"b_mode_t_G_READ");
strcpy(_b_mode_tG_WRITE,"b_mode_t_G_WRITE");
strcpy(_b_mode_tG_EXEC,"b_mode_t_G_EXEC");
strcpy(_b_mode_tG_NONE,"b_mode_t_G_NONE");
strcpy(_b_mode_tO_READ,"b_mode_t_O_READ");
strcpy(_b_mode_tO_WRITE,"b_mode_t_O_WRITE");
strcpy(_b_mode_tO_EXEC,"b_mode_t_O_EXEC");
strcpy(_b_mode_tO_NONE,"b_mode_t_O_NONE");
strcpy(_b_mode_tUID_SET,"b_mode_t_UID_SET");
strcpy(_b_mode_tUID_CLEAR,"b_mode_t_UID_CLEAR");
strcpy(_b_mode_tGID_SET,"b_mode_t_GID_SET");
strcpy(_b_mode_tGID_CLEAR,"b_mode_t_GID_CLEAR");
}

//--------------------------------------------------------------------
b_param *b_mode_t::b_mode_tU_READ()
{
   return &_b_mode_tU_READ;
}

b_param *b_mode_t::b_mode_tU_WRITE()
{
   return &_b_mode_tU_WRITE;
}

b_param *b_mode_t::b_mode_tU_EXEC()
{
   return &_b_mode_tU_EXEC;
}

b_param *b_mode_t::b_mode_tU_RWX()
{
   return &_b_mode_tU_RWX;
}

b_param *b_mode_t::b_mode_tU_NONE()
{
   return &_b_mode_tU_NONE;
}

b_param *b_mode_t::b_mode_tG_READ()
{
   return &_b_mode_tG_READ;
}

b_param *b_mode_t::b_mode_tG_WRITE()
{
   return &_b_mode_tG_WRITE;
}

b_param *b_mode_t::b_mode_tG_EXEC()
{
   return &_b_mode_tG_EXEC;
}

b_param *b_mode_t::b_mode_tG_NONE()
{
   return &_b_mode_tG_NONE;
}

b_param *b_mode_t::b_mode_tO_READ()
{
   return &_b_mode_tO_READ;
}

b_param *b_mode_t::b_mode_tO_WRITE()
{
   return &_b_mode_tO_WRITE;
}

b_param *b_mode_t::b_mode_tO_EXEC()
{
   return &_b_mode_tO_EXEC;
}

b_param *b_mode_t::b_mode_tO_NONE()
{
   return &_b_mode_tO_NONE;
}

b_param *b_mode_t::b_mode_tUID_SET()
{
   return &_b_mode_tUID_SET;
}

b_param *b_mode_t::b_mode_tUID_CLEAR()
{
   return &_b_mode_tUID_CLEAR;
}

b_param *b_mode_t::b_mode_tGID_SET()
{
   return &_b_mode_tGID_SET;
}

b_param *b_mode_t::b_mode_tGID_CLEAR()
{
   return &_b_mode_tGID_CLEAR;
}

//--------------------------------------------------------------------
//---------------------------------------------------------------------------
//type name return method

b_param *CLASSNAME::typeName()
{
  return &_b_mode_tTYPENAME;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int CLASSNAME::distanceFromBase()
{
  return CLASSPARENT::distanceFromBase() +1;
}


//---------------------------------------------------------------------------
void CLASSNAME::typeList(b_param list[], int num)
{
  strcpy(list[num],(char *) typeName());
  CLASSPARENT::typeList(list,num+1);
}
//--------------------------------------------------------------------
  void *CLASSNAME::access(b_param data[])
{
  if (strcmp(data[0],(char *)typeName())!=0)
    return CLASSPARENT::access(data);

  //ACCESS CODE
b_mode_t_u_read = 0;
b_mode_t_u_write = 0;
b_mode_t_u_exec = 0;
b_mode_t_u_rwx = 0;
b_mode_t_u_none = 0;
b_mode_t_g_read = 0;
b_mode_t_g_write = 0;
b_mode_t_g_exec = 0;
b_mode_t_g_none = 0;
b_mode_t_o_read = 0;
b_mode_t_o_write = 0;
b_mode_t_o_exec = 0;
b_mode_t_o_none = 0;
b_mode_t_uid_set = 0;
b_mode_t_uid_clear = 0;
b_mode_t_gid_set = 0;
b_mode_t_gid_clear = 0;
   int dataPTR =0;


   dataPTR++;
if (strcmp(data[dataPTR],_b_mode_tU_READ)==0)
      b_mode_t_u_read = 1;
   else if (strcmp(data[dataPTR],_b_mode_tU_WRITE)==0)
      b_mode_t_u_write = 1;
   else if (strcmp(data[dataPTR],_b_mode_tU_EXEC)==0)
      b_mode_t_u_exec = 1;
   else if (strcmp(data[dataPTR],_b_mode_tU_RWX)==0)
      b_mode_t_u_rwx = 1;
   else if (strcmp(data[dataPTR],_b_mode_tU_NONE)==0)
      b_mode_t_u_none = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"OWNER"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_mode_tG_READ)==0)
      b_mode_t_g_read = 1;
   else if (strcmp(data[dataPTR],_b_mode_tG_WRITE)==0)
      b_mode_t_g_write = 1;
   else if (strcmp(data[dataPTR],_b_mode_tG_EXEC)==0)
      b_mode_t_g_exec = 1;
   else if (strcmp(data[dataPTR],_b_mode_tG_NONE)==0)
      b_mode_t_g_none = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"GROUP"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_mode_tO_READ)==0)
      b_mode_t_o_read = 1;
   else if (strcmp(data[dataPTR],_b_mode_tO_WRITE)==0)
      b_mode_t_o_write = 1;
   else if (strcmp(data[dataPTR],_b_mode_tO_EXEC)==0)
      b_mode_t_o_exec = 1;
   else if (strcmp(data[dataPTR],_b_mode_tO_NONE)==0)
      b_mode_t_o_none = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"OTHER"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_mode_tUID_SET)==0)
      b_mode_t_uid_set = 1;
   else if (strcmp(data[dataPTR],_b_mode_tUID_CLEAR)==0)
      b_mode_t_uid_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"S_ISUID"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_mode_tGID_SET)==0)
      b_mode_t_gid_set = 1;
   else if (strcmp(data[dataPTR],_b_mode_tGID_CLEAR)==0)
      b_mode_t_gid_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"S_ISGID"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

_theVariable = 0;

if (b_mode_t_u_read==1)
{

 _theVariable = (_theVariable | S_IRUSR);
 
}

if (b_mode_t_u_write==1)
{

 _theVariable = (_theVariable | S_IWUSR);
 
}

if (b_mode_t_u_exec==1)
{

 _theVariable = (_theVariable | S_IXUSR);
 
}

if (b_mode_t_u_rwx==1)
{

 _theVariable = (_theVariable | S_IRUSR | S_IWUSR | S_IXUSR);
 
}

if (b_mode_t_g_read==1)
{

 _theVariable = (_theVariable | S_IRGRP);
 
}

if (b_mode_t_g_write==1)
{

 _theVariable = (_theVariable | S_IWGRP);
 
}

if (b_mode_t_g_exec==1)
{

 _theVariable = (_theVariable | S_IXGRP);
 
}

if (b_mode_t_o_read==1)
{

 _theVariable = (_theVariable | S_IROTH);
 
}

if (b_mode_t_o_write==1)
{

 _theVariable = (_theVariable | S_IWOTH);
 
}

if (b_mode_t_o_exec==1)
{

 _theVariable = (_theVariable | S_IXOTH);
 
}

if (b_mode_t_uid_set==1)
{

 _theVariable = (_theVariable | S_ISUID);
 
}

if (b_mode_t_gid_set==1)
{

 _theVariable = (_theVariable | S_ISGID);
 
}
   return &_theVariable;
}

//--------------------------------------------------------------------
  int CLASSNAME::commit(b_param tname)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::commit(tname);
  //COMMIT CODE HERE
//generated
   return 0;
}

//--------------------------------------------------------------------
  int CLASSNAME::cleanup(b_param tname)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::cleanup(tname);
      
  //CLEANUP CODE
//generated
   return 0;
}

//--------------------------------------------------------------------
int CLASSNAME::numDials(b_param tname)
{
  if (!strcmp(tname,(char *)typeName()))
    return NUMBER_OF_DIALS;
  else return CLASSPARENT::numDials(tname);
      
}


//---------------------------------------------------------------------------
int CLASSNAME::numItems(b_param tname,int dialNumber)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::numItems(tname,dialNumber);
  switch (dialNumber)
    {
      //NUMITEMS SWITCH CASES HERE
      //generated

   case 1:
      return 5;
      break;

   case 2:
      return 4;
      break;

   case 3:
      return 4;
      break;

   case 4:
      return 2;
      break;

   case 5:
      return 2;
      break;
//---------------------------------------------------------------------------
      //end generated

    default:
      cerr<<"Error, invalid dial number passed to "
          <<CLASS_STRING<<"::numItems\n"
          <<"Please check declaration files.  Dial number passed was "
          <<dialNumber<<endl;
      exit(1);
    }
  return 0;
}

//---------------------------------------------------------------------------
b_param *CLASSNAME::paramName(b_param tname,
                                   int dialNumber,
                                   int position)

{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::paramName(tname,dialNumber,position);
  
  switch (dialNumber)
    {
      //PARAMNAME SWITCH CASES HERE
      //generated

case 1:
 switch (position)
   {
      case 1:
         return b_mode_tU_READ();
         break;
      case 2:
         return b_mode_tU_WRITE();
         break;
      case 3:
         return b_mode_tU_EXEC();
         break;
      case 4:
         return b_mode_tU_RWX();
         break;
      case 5:
         return b_mode_tU_NONE();
         break;

      default:
          cerr<<"Error, invalid position number passed to "
              <<CLASS_STRING<<"::paramName\n"
              <<"Please check declaration files.  Dial number passed was"
              <<dialNumber<<" position "<<position<<".\n";
          exit(1);
   }
   break;

case 2:
 switch (position)
   {
      case 1:
         return b_mode_tG_READ();
         break;
      case 2:
         return b_mode_tG_WRITE();
         break;
      case 3:
         return b_mode_tG_EXEC();
         break;
      case 4:
         return b_mode_tG_NONE();
         break;

      default:
          cerr<<"Error, invalid position number passed to "
              <<CLASS_STRING<<"::paramName\n"
              <<"Please check declaration files.  Dial number passed was"
              <<dialNumber<<" position "<<position<<".\n";
          exit(1);
   }
   break;

case 3:
 switch (position)
   {
      case 1:
         return b_mode_tO_READ();
         break;
      case 2:
         return b_mode_tO_WRITE();
         break;
      case 3:
         return b_mode_tO_EXEC();
         break;
      case 4:
         return b_mode_tO_NONE();
         break;

      default:
          cerr<<"Error, invalid position number passed to "
              <<CLASS_STRING<<"::paramName\n"
              <<"Please check declaration files.  Dial number passed was"
              <<dialNumber<<" position "<<position<<".\n";
          exit(1);
   }
   break;

case 4:
 switch (position)
   {
      case 1:
         return b_mode_tUID_SET();
         break;
      case 2:
         return b_mode_tUID_CLEAR();
         break;

      default:
          cerr<<"Error, invalid position number passed to "
              <<CLASS_STRING<<"::paramName\n"
              <<"Please check declaration files.  Dial number passed was"
              <<dialNumber<<" position "<<position<<".\n";
          exit(1);
   }
   break;

case 5:
 switch (position)
   {
      case 1:
         return b_mode_tGID_SET();
         break;
      case 2:
         return b_mode_tGID_CLEAR();
         break;

      default:
          cerr<<"Error, invalid position number passed to "
              <<CLASS_STRING<<"::paramName\n"
              <<"Please check declaration files.  Dial number passed was"
              <<dialNumber<<" position "<<position<<".\n";
          exit(1);
   }
   break;
    default:
      cerr<<"Error, invalid dial number passed to "
          <<CLASS_STRING<<"::paramName\n"
          <<"Please check declaration files.  Dial number passed was "
          <<dialNumber<<endl;
      exit(1);

    }
  return NULL;
}

//---------------------------------------------------------------------------
