Skip to content
Snippets Groups Projects
Select Git revision
  • b6164325fbd3eeaf5f9800d89be2ab6f4387e66b
  • master default
  • library-names
  • fix_script_header
  • fix_libdir
  • fix_cmake_hdf5
  • partition
  • cgnsUnstructured
  • partitioning
  • HighOrderBLCurving
  • gmsh_3_0_5
  • gmsh_3_0_4
  • gmsh_3_0_3
  • gmsh_3_0_2
  • gmsh_3_0_1
  • gmsh_3_0_0
  • gmsh_2_16_0
  • gmsh_2_15_0
  • gmsh_2_14_1
  • gmsh_2_14_0
  • gmsh_2_13_2
  • gmsh_2_13_1
  • gmsh_2_12_0
  • gmsh_2_11_0
  • gmsh_2_10_1
  • gmsh_2_10_0
  • gmsh_2_9_3
  • gmsh_2_9_2
  • gmsh_2_9_1
  • gmsh_2_9_0
30 results

FunctionManager.cpp

Blame
  • Forked from gmsh / gmsh
    Source project has a limited visibility.
    FunctionManager.cpp 1.82 KiB
    /* $Id: FunctionManager.cpp,v 1.5 2001-01-01 20:48:40 geuzaine Exp $ */
    #include <stdio.h>
    #include <stack>
    #include <map>
    #include "FunctionManager.h"
    
    struct ltstr
    {
      bool operator()(const char* s1, const char* s2) const
      {
        return strcmp(s1, s2) < 0;
      }
    };
    
    class File_Position 
    {
      public :
        int lineno;
        fpos_t position;
        FILE *file;
    };
    
    // Pour utiliser un namespace global sur SGI, il faut compiler avec
    // -LANG:std, et ajouter "use namespace std;". Dans tous les cas, il
    // FAUT creer les librairies avec 'CC -ar', et pas avec 'ar'.
    
    class mystack
    {
    public:
      //std::stack<File_Position> s;
      stack<File_Position> s;
    };
    class mymap
    {
    public :
      //std::map<char*,File_Position,ltstr> m;
      map<char*,File_Position,ltstr> m;
    };
    
    FunctionManager *FunctionManager::instance = 0;
    
    FunctionManager::FunctionManager()
    {
      functions = new mymap;
      calls = new mystack;
    }
    
    FunctionManager* FunctionManager::Instance()
    {
      if(!instance)
        {
          instance = new FunctionManager;
        }
      return instance;
    }
    
    bool FunctionManager::enterFunction(char *name, FILE **f, int &lno) const
    {
      if(functions->m.find(name) == functions->m.end())return false;
      File_Position fpold;
      fpold.lineno = lno;
      fpold.file = *f;
      fgetpos(fpold.file,&fpold.position);
      calls->s.push(fpold);
      File_Position fp = (functions->m)[name];
      fsetpos(fp.file,&fp.position);
      *f = fp.file;
      lno = fp.lineno;
      return true;
    }
    
    bool FunctionManager::leaveFunction(FILE **f,int &lno)
    {
      if(!calls->s.size())return false;
      File_Position fp;
      fp = calls->s.top();
      calls->s.pop();
      fsetpos(fp.file,&fp.position);
      *f = fp.file;
      lno = fp.lineno;
      return true;
    }
    
    bool FunctionManager::createFunction(char *name, FILE *f, int lno)
    {
      File_Position fp;
      fp.file = f;
      fp.lineno = lno;
      fgetpos(fp.file,&fp.position);
      (functions->m)[name] = fp;
      return true;
    }