Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
a8ed08f7
Commit
a8ed08f7
authored
24 years ago
by
Jean-François Remacle
Browse files
Options
Downloads
Patches
Plain Diff
Management of functions
parent
4cd92eab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Parser/FunctionManager.cpp
+84
-0
84 additions, 0 deletions
Parser/FunctionManager.cpp
Parser/FunctionManager.h
+25
-0
25 additions, 0 deletions
Parser/FunctionManager.h
examples/function.geo
+57
-0
57 additions, 0 deletions
examples/function.geo
with
166 additions
and
0 deletions
Parser/FunctionManager.cpp
0 → 100644
+
84
−
0
View file @
a8ed08f7
#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
;
}
This diff is collapsed.
Click to expand it.
Parser/FunctionManager.h
0 → 100644
+
25
−
0
View file @
a8ed08f7
#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
This diff is collapsed.
Click to expand it.
examples/function.geo
0 → 100644
+
57
−
0
View file @
a8ed08f7
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment