Skip to content
Snippets Groups Projects
Commit a8ed08f7 authored by Jean-François Remacle's avatar Jean-François Remacle
Browse files

Management of functions

parent 4cd92eab
Branches
Tags
No related merge requests found
#include "FunctionManager.h"
#include <stdio.h>
#include <stack>
#include <map>
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
class File_Position
{
public :
fpos_t position;
FILE *file;
};
class mystack
{
public:
std::stack<File_Position> s;
};
class mymap
{
public :
std::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) const
{
if(functions->m.find(name) == functions->m.end())return false;
File_Position fpold;
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;
return true;
}
bool FunctionManager::leaveFunction(FILE **f)
{
if(!calls->s.size())return false;
File_Position fp;
fp = calls->s.top();
calls->s.pop();
fsetpos(fp.file,&fp.position);
*f = fp.file;
return true;
}
bool FunctionManager::createFunction(char *name, FILE *f)
{
File_Position fp;
fp.file = f;
fgetpos(fp.file,&fp.position);
(functions->m)[name] = fp;
return true;
}
#ifndef _FUNCTION_MANAGER_H_
#define _FUNCTION_MANAGER_H_
class mystack;
class mymap;
#include <stdio.h>
/*
Singleton, one function manager for
all parsers.
*/
class FunctionManager
{
mymap *functions;
mystack *calls;
FunctionManager ();
static FunctionManager *instance;
public :
static FunctionManager* Instance();
bool enterFunction (char *name, FILE **f) const;
bool createFunction (char *name, FILE *f);
bool leaveFunction (FILE **f);
};
#endif
x = 0;
y = 0;
r = 1;
theloop = 0;
Function myCircle
p1 = newp;
Point (p1) = {x,y,0,0.2};
p2 = newp;
Point (p2) = {r+x,y,0,0.2};
p3 = newp;
Point (p3) = {x,r+y,0,0.2};
p4 = newp;
Point (p4) = {-r+x,y,0,0.2};
p5 = newp;
Point (p5) = {x,-r+y,0,0.2};
c1 = newreg;
Circle (c1) = {p2,p1,p3};
c2 = newreg;
Circle (c2) = {p3,p1,p4};
c3 = newreg;
Circle (c3) = {p4,p1,p5};
c4 = newreg;
Circle (c4) = {p5,p1,p2};
theloop = newreg;
Line Loop (theloop) = {c1,c2,c3,c4};
Return
x = 2;
y = 2;
Call myCircle;
/*loop,x,y and r should be parameters*/
loop1 = theloop;
x = -2;
y = 2;
Call myCircle;
loop2 = theloop;
x = 2;
y = -2;
Call myCircle;
loop3 = theloop;
x = -2;
y = -2;
Call myCircle;
loop4 = theloop;
r = 5;
x = 0;
y = 0;
Call myCircle;
loop5 = theloop;
Plane Surface(newreg) = {loop5,loop4,loop3,loop2,loop1};
Line(10000) = {6,11};
Attractor Line {10000} = {1,.03,1};
Mesh.Algorithm = 2 ; // This is the new 2D anisotropic algorithm
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment