Created a wrapper for a function in a class.


 
Thread Tools Search this Thread
Top Forums Programming Created a wrapper for a function in a class.
# 1  
Old 02-14-2012
Created a wrapper for a function in a class.

I have a class called Parsing with the following function. I want to create a wrapper for it, so that I call it using GetReal rather than GetFloat.

Bit confused on how to do this.

Code:
class Parsing {

private:

  int  Length;                         //
  int  Ptr;                            //
  List<ParseEl>  Index;                //

public:

  Parsing();                           //

  Parsing(                             //
    const int  argc,
    char*  argv[]);

  Parsing(                             //
    istream&  is);

  void  ParseFile(                     //
    istream&  is);

  void  ParseCmd(                      //
    const int  argc,
    char*  argv[]);

  bool  GetFloat(                      // Get a floating point number.
    const String&  Id,
    float&  f,
    const int  ord1,
    const int  ord2,
    const int  ord3);

  bool  GetReal(                      // Wrapper function for GetFloat.
    const String&  Id,
    float&  f,
    const int  ord1,
    const int  ord2,
    const int  ord3);

  bool  GetFloat(                      // Get a floating point number.
    const char*  Id,
    float&  f,
    const int  ord1,
    const int  ord2,
    const int  ord3);

  bool  GetReal(                       // Wrapper function for GetFloat.
    const char*  Id,
    float&  f,
    const int  ord1,
    const int  ord2,
    const int  ord3);

private:

  bool  GetFloat(                      // Get a floating point number.
    const char*  Id,
    float&  f,
    const List<int>&  ord);

  bool  GetReal(                      // Wrapper function for GetFloat.
    const char*  Id,
    float&  f,
    const List<int>&  ord);

};

////////////////////////////////////////////////////////////////////////////////////////////////////

inline bool  Parsing::GetFloat(
  const String&  Id,
  float&  f,
  const int  ord1 = 0,
  const int  ord2 = 0,
  const int  ord3 = 0) {

  return GetFloat( (char *)Id, f, ord1, ord2, ord3 );

}

////////////////////////////////////////////////////////////////////////////////////////////////////

inline bool  Parsing::GetReal(
  const String&  Id,
  float&  f,
  const int  ord1 = 0,
  const int  ord2 = 0,
  const int  ord3 = 0) {

  return GetFloat( (char *)Id, f, ord1, ord2, ord3 );

}

////////////////////////////////////////////////////////////////////////////////////////////////////

bool  Parsing::GetFloat(
  const char*  Id,
  float&  f,
  const int  ord1 = 0,
  const int  ord2 = 0,
  const int  ord3 = 0 ) {

  List<int>  L;

  if (ord1 != 0) {
      L += ord1;
      if (ord2 != 0) {
          L += ord2;
          if (ord3 != 0) { L += ord3; }
      }
  }

  return GetFloat(Id, f, L);

}

////////////////////////////////////////////////////////////////////////////////////////////////////

bool  Parsing::GetReal(
  const char*  Id,
  float&  f,
  const int  ord1 = 0,
  const int  ord2 = 0,
  const int  ord3 = 0 ) {

  List<int>  L;

  if (ord1 != 0) {
      L += ord1;
      if (ord2 != 0) {
          L += ord2;
          if (ord3 != 0) { L += ord3; }
      }
  }

  return GetFloat(Id, f, L);

}

////////////////////////////////////////////////////////////////////////////////////////////////////

bool  Parsing::GetFloat(
  const char*  Id,
  float&  f,
  const List<int>&  ord) {

  int  j;
  int  found = -1;
  int  HId = Hash(Id);

  j = Ptr;
  if (Index.size() == 0) { return false; }

  do {
      if ( (Index[j].Hash == HId) && (Index[j].Type == PARAM)
        && (Index[j].Name == String(Id)) && (Index[j].Ord  == ord) ) {
          found = j;
      }
      j++;
      if (j == Index.size()) { j = 0; }
  } while ((found == -1) && (j != Ptr));

  if (found == -1) { return false; }

  Index[found].Str.Rewind();
  Index[found].Str >> f;
  Ptr = found;
  if (Ptr == Index.size()) { Ptr = 0; }
  return true;

}

////////////////////////////////////////////////////////////////////////////////////////////////////

bool  Parsing::GetReal(
  const char*  Id,
  float&  f,
  const List<int>&  ord) {

  int  j;
  int  found = -1;
  int  HId = Hash(Id);

  j = Ptr;
  if (Index.size() == 0) { return false; }

  do {
      if ( (Index[j].Hash == HId) && (Index[j].Type == PARAM)
        && (Index[j].Name == String(Id)) && (Index[j].Ord  == ord) ) {
          found = j;
      }
      j++;
      if (j == Index.size()) { j = 0; }
  } while ((found == -1) && (j != Ptr));

  if (found == -1) { return false; }

  Index[found].Str.Rewind();
  Index[found].Str >> f;
  Ptr = found;
  if (Ptr == Index.size()) { Ptr = 0; }
  return true;

}


Last edited by kristinu; 02-14-2012 at 10:06 AM..
# 2  
Old 02-15-2012
If it is just a synonym, have GetReal call GetFloat(). The compiler can inline it, saving the extra call, just like you do for char*/String&.

Last edited by DGPickett; 02-15-2012 at 05:44 PM..
# 3  
Old 02-15-2012
Didn't you already ask this in a different thread, and get the exact same answer?
# 4  
Old 02-15-2012
Well, then, I like their answer, too! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Local variable in a C function is not getting created in stack when its compiled with GCC

Hi, I am working in UEFI EDK2 Bios source. We created a platform related new package in the EDK2 source. I find a strange issue with the platform related code we added. When I did source level debugging I noticed the local variable in a C function is not getting created in stack when its... (6 Replies)
Discussion started by: Divya R
6 Replies

2. Programming

C++ : Base class member function not accessible from derived class

Hello All, I am a learner in C++. I was testing my inheritance knowledge with following piece of code. #include <iostream> using namespace std; class base { public : void display() { cout << "In base display()" << endl; } void display(int k) {... (2 Replies)
Discussion started by: anand.shah
2 Replies

3. Programming

passing object to function, columns class

I am working on a small columns class, since I use allot of tabular data. I am trying to set up code to allow me to efficiently read in tabular data, manipulate it, and write to output files. I more or less know what I need to do, but there are many options to sort through. I have the beginnings... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

4. Programming

Handling a signal with a class member function

Hello, i am using the sigaction function to handle the SIGCHLD signal.Is it possible to use a class member function as the handler function (the sa_handler member of the sigaction structure)? The function's signature is: void (*sa_handler)(int);so i don't think i can use a static member function... (2 Replies)
Discussion started by: Zipi
2 Replies

5. Shell Programming and Scripting

Function loading in a shell scripting like class loading in java

Like class loader in java, can we make a function loader in shell script, for this can someone throw some light on how internally bash runs a shell script , what happenes in runtime ... thanks in advance.. (1 Reply)
Discussion started by: mpsc_sela
1 Replies

6. Programming

How to make a function friend to both base and derived class

Hi, I have a base class and derived a class from the base class, i want to print & read the data for the object created for the derived class,so i have overloaded both the << and >> operators and also have done the foward declaration. Below is the code snippet, #include <iostream> class... (3 Replies)
Discussion started by: ennstate
3 Replies

7. Programming

how to write a wrapper c code to return uid using getuid() function

And how to use setuid() ? thanks (4 Replies)
Discussion started by: pwd
4 Replies

8. Shell Programming and Scripting

Passing a variable name to be created within a function

Is it possible to pass a variable name, as a parameter to a function, so it can be created within this function ? Something like this: func_uppercase abcdefgh var_name where the 1st parameter is the string I want to convert and the 2nd is the desired variable name... $2=`echo "$1" |... (2 Replies)
Discussion started by: 435 Gavea
2 Replies
Login or Register to Ask a Question