/*
   b_oflag.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 06:41 PM EDT

TITLE
   b_oflag.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_oflag.h"

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

 

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

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

  //generated

   strcpy(_b_oflagTYPENAME,CLASS_STRING);
strcpy(_b_oflagRDONLY_SET,"b_oflag_RDONLY_SET");
strcpy(_b_oflagWRONLY_SET,"b_oflag_WRONLY_SET");
strcpy(_b_oflagRDWR_SET,"b_oflag_RDWR_SET");
strcpy(_b_oflagNONE,"b_oflag_NONE");
strcpy(_b_oflagA_SET,"b_oflag_A_SET");
strcpy(_b_oflagA_CLEAR,"b_oflag_A_CLEAR");
strcpy(_b_oflagC_SET,"b_oflag_C_SET");
strcpy(_b_oflagC_CLEAR,"b_oflag_C_CLEAR");
strcpy(_b_oflagD_SET,"b_oflag_D_SET");
strcpy(_b_oflagD_CLEAR,"b_oflag_D_CLEAR");
strcpy(_b_oflagE_SET,"b_oflag_E_SET");
strcpy(_b_oflagE_CLEAR,"b_oflag_E_CLEAR");
strcpy(_b_oflagNCT_SET,"b_oflag_NCT_SET");
strcpy(_b_oflagNCT_CLEAR,"b_oflag_NCT_CLEAR");
strcpy(_b_oflagNBLK_SET,"b_oflag_NBLK_SET");
strcpy(_b_oflagNBLK_CLEAR,"b_oflag_NBLK_CLEAR");
strcpy(_b_oflagR_SET,"b_oflag_R_SET");
strcpy(_b_oflagR_CLEAR,"b_oflag_R_CLEAR");
strcpy(_b_oflagSYNC_SET,"b_oflag_SYNC_SET");
strcpy(_b_oflagSYNC_CLEAR,"b_oflag_SYNC_CLEAR");
strcpy(_b_oflagT_SET,"b_oflag_T_SET");
strcpy(_b_oflagT_CLEAR,"b_oflag_T_CLEAR");
}

//--------------------------------------------------------------------
b_param *b_oflag::b_oflagRDONLY_SET()
{
   return &_b_oflagRDONLY_SET;
}

b_param *b_oflag::b_oflagWRONLY_SET()
{
   return &_b_oflagWRONLY_SET;
}

b_param *b_oflag::b_oflagRDWR_SET()
{
   return &_b_oflagRDWR_SET;
}

b_param *b_oflag::b_oflagNONE()
{
   return &_b_oflagNONE;
}

b_param *b_oflag::b_oflagA_SET()
{
   return &_b_oflagA_SET;
}

b_param *b_oflag::b_oflagA_CLEAR()
{
   return &_b_oflagA_CLEAR;
}

b_param *b_oflag::b_oflagC_SET()
{
   return &_b_oflagC_SET;
}

b_param *b_oflag::b_oflagC_CLEAR()
{
   return &_b_oflagC_CLEAR;
}

b_param *b_oflag::b_oflagD_SET()
{
   return &_b_oflagD_SET;
}

b_param *b_oflag::b_oflagD_CLEAR()
{
   return &_b_oflagD_CLEAR;
}

b_param *b_oflag::b_oflagE_SET()
{
   return &_b_oflagE_SET;
}

b_param *b_oflag::b_oflagE_CLEAR()
{
   return &_b_oflagE_CLEAR;
}

b_param *b_oflag::b_oflagNCT_SET()
{
   return &_b_oflagNCT_SET;
}

b_param *b_oflag::b_oflagNCT_CLEAR()
{
   return &_b_oflagNCT_CLEAR;
}

b_param *b_oflag::b_oflagNBLK_SET()
{
   return &_b_oflagNBLK_SET;
}

b_param *b_oflag::b_oflagNBLK_CLEAR()
{
   return &_b_oflagNBLK_CLEAR;
}

b_param *b_oflag::b_oflagR_SET()
{
   return &_b_oflagR_SET;
}

b_param *b_oflag::b_oflagR_CLEAR()
{
   return &_b_oflagR_CLEAR;
}

b_param *b_oflag::b_oflagSYNC_SET()
{
   return &_b_oflagSYNC_SET;
}

b_param *b_oflag::b_oflagSYNC_CLEAR()
{
   return &_b_oflagSYNC_CLEAR;
}

b_param *b_oflag::b_oflagT_SET()
{
   return &_b_oflagT_SET;
}

b_param *b_oflag::b_oflagT_CLEAR()
{
   return &_b_oflagT_CLEAR;
}

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

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

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
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_oflag_rdonly_set = 0;
b_oflag_wronly_set = 0;
b_oflag_rdwr_set = 0;
b_oflag_none = 0;
b_oflag_a_set = 0;
b_oflag_a_clear = 0;
b_oflag_c_set = 0;
b_oflag_c_clear = 0;
b_oflag_d_set = 0;
b_oflag_d_clear = 0;
b_oflag_e_set = 0;
b_oflag_e_clear = 0;
b_oflag_nct_set = 0;
b_oflag_nct_clear = 0;
b_oflag_nblk_set = 0;
b_oflag_nblk_clear = 0;
b_oflag_r_set = 0;
b_oflag_r_clear = 0;
b_oflag_sync_set = 0;
b_oflag_sync_clear = 0;
b_oflag_t_set = 0;
b_oflag_t_clear = 0;
   int dataPTR =0;


   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagRDONLY_SET)==0)
      b_oflag_rdonly_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagWRONLY_SET)==0)
      b_oflag_wronly_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagRDWR_SET)==0)
      b_oflag_rdwr_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagNONE)==0)
      b_oflag_none = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"ACCESS"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagA_SET)==0)
      b_oflag_a_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagA_CLEAR)==0)
      b_oflag_a_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_APPEND"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagC_SET)==0)
      b_oflag_c_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagC_CLEAR)==0)
      b_oflag_c_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_CREAT"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagD_SET)==0)
      b_oflag_d_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagD_CLEAR)==0)
      b_oflag_d_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_DSYNC"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagE_SET)==0)
      b_oflag_e_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagE_CLEAR)==0)
      b_oflag_e_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_EXCL"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagNCT_SET)==0)
      b_oflag_nct_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagNCT_CLEAR)==0)
      b_oflag_nct_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_NOCTTY"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagNBLK_SET)==0)
      b_oflag_nblk_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagNBLK_CLEAR)==0)
      b_oflag_nblk_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_NONBLOCK"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagR_SET)==0)
      b_oflag_r_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagR_CLEAR)==0)
      b_oflag_r_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_RSYNC"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagSYNC_SET)==0)
      b_oflag_sync_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagSYNC_CLEAR)==0)
      b_oflag_sync_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_SYNC"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_oflagT_SET)==0)
      b_oflag_t_set = 1;
   else if (strcmp(data[dataPTR],_b_oflagT_CLEAR)==0)
      b_oflag_t_clear = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"O_TRUNC"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }
_theVariable = 0;
if (b_oflag_rdonly_set==1)
{
_theVariable |= O_RDONLY; 
}

if (b_oflag_wronly_set==1)
{
_theVariable |= O_WRONLY; 
}

if (b_oflag_rdwr_set==1)
{
_theVariable |= O_RDWR; 
}

if (b_oflag_a_set==1)
{
_theVariable |= O_APPEND; 
}

if (b_oflag_c_set==1)
{
_theVariable |= O_CREAT; 
}

if (b_oflag_d_set==1)
{
_theVariable |= O_DSYNC; 
}

if (b_oflag_e_set==1)
{
_theVariable |= O_EXCL; 
}

if (b_oflag_nct_set==1)
{
_theVariable |= O_NOCTTY; 
}

if (b_oflag_nblk_set==1)
{
_theVariable |= O_NONBLOCK; 
}

if (b_oflag_r_set==1)
{
_theVariable |= O_RSYNC; 
}

if (b_oflag_sync_set==1)
{
_theVariable |= O_SYNC; 
}

if (b_oflag_t_set==1)
{
_theVariable |= O_TRUNC; 
}
   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 4;
      break;

   case 2:
      return 2;
      break;

   case 3:
      return 2;
      break;

   case 4:
      return 2;
      break;

   case 5:
      return 2;
      break;

   case 6:
      return 2;
      break;

   case 7:
      return 2;
      break;

   case 8:
      return 2;
      break;

   case 9:
      return 2;
      break;

   case 10:
      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_oflagRDONLY_SET();
         break;
      case 2:
         return b_oflagWRONLY_SET();
         break;
      case 3:
         return b_oflagRDWR_SET();
         break;
      case 4:
         return b_oflagNONE();
         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_oflagA_SET();
         break;
      case 2:
         return b_oflagA_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 3:
 switch (position)
   {
      case 1:
         return b_oflagC_SET();
         break;
      case 2:
         return b_oflagC_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 4:
 switch (position)
   {
      case 1:
         return b_oflagD_SET();
         break;
      case 2:
         return b_oflagD_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_oflagE_SET();
         break;
      case 2:
         return b_oflagE_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 6:
 switch (position)
   {
      case 1:
         return b_oflagNCT_SET();
         break;
      case 2:
         return b_oflagNCT_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 7:
 switch (position)
   {
      case 1:
         return b_oflagNBLK_SET();
         break;
      case 2:
         return b_oflagNBLK_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 8:
 switch (position)
   {
      case 1:
         return b_oflagR_SET();
         break;
      case 2:
         return b_oflagR_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 9:
 switch (position)
   {
      case 1:
         return b_oflagSYNC_SET();
         break;
      case 2:
         return b_oflagSYNC_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 10:
 switch (position)
   {
      case 1:
         return b_oflagT_SET();
         break;
      case 2:
         return b_oflagT_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;
}

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