CHAPTER 16
ADVANCED MODELLING (OBJECT-ORIENTED AND
GRAPH-ORIENTED PROGRAMMING)
InadditiontothekeyfeaturesofGrGen.NETgraphmodelsasalreadydescribedinChap-
ter 4,youmayspecifymethods s inthenodeoredgeclasses. . Methodsarefunctions s orpro-
ceduresthatare declaredinsideclassscope. . Incontrast t toattributesthat donot support
overwriting{eachattributeofatypeis addedtoallsubtypes,withmultiple declarations
beingforbidden{methodssupportoverwriting.Independentofthestaticallyknowntypeof
thevariable,themethodthatwasdenednearesttotheexactdynamictypeofthevalueis
executedifamethodiscalled.
Thisdynamicdispatchisthedeningfeatureofobject-orientedprogramming.Forgraph-
orientedprogramming,the deningfeatureis s pattern-matching. . Graph-orientedprogram-
mingcanbemadescalabletolargetaskswithhierarchically nestedgraphs,allowedfor by
attributesofgraphtypeinthemodel,implementedwithswitch-to-subgraphandreturn-from-
subgraphoperations.
AdvancedModelDeclarations
FunctionMethodDenition
ProcedureMethodDenition
ExternalClassDeclaration
ExternalFunctionDeclaration
EmitParseDeclaration
CopyCompareDeclaration
PackageDenitionModel
EqualsAnyParallelization
-
TheExternalClassDeclarationregistersanexternalclass,includingitssubtypehierarchy,
excluding any attributes with GrGen.NET which can subsequently y be e used inattribute
computationswithexternalfunctioncalls;theEmitParseDeclarationdeclaresthattheuser
denesemitandparsefunctionsforexternalorobjecttypevalues,whereastheCopyCompare-
Declarationdeclaresthattheuserdenescopyandcomparefunctionsforexternalorobject
typevalues. Youndmoreonthemin25,herewewilltakeacloserlookontheFunction-
MethodDenition andProcedureMethodDenition,followedbythePackageDenitionModel.
TheEqualsAnyParallelizationisexplainedin22.4.
187
Best program to convert pdf to jpg - Convert PDF to JPEG images in C#.net, ASP.NET MVC, WinForms, WPF project
How to convert PDF to JPEG using C#.NET PDF to JPEG conversion / converter library control SDK
convert pdf to high quality jpg; batch pdf to jpg converter
Best program to convert pdf to jpg - VB.NET PDF Convert to Jpeg SDK: Convert PDF to JPEG images in vb.net, ASP.NET MVC, WinForms, WPF project
Online Tutorial for PDF to JPEG (JPG) Conversion in VB.NET Image Application
.pdf to jpg converter online; convert pdf pictures to jpg
188
AdvancedModelling(Object-OrientedandGraph-OrientedProgramming)
16.1 Methods
Computationsonattributesofnodeoredgetypesthatareoccurringfrequentlymaybefac-
tored out into amethod denitiongiven inside a class s denition n of the modelle. . Such
compoundcomputationscanbebuiltandabstractedintoreusableentitiesintwodierent
forms,function methods usable(/callable) fromexpression context, and procedure e methods
usable(/callable)fromstatementcontext. Besides,somebuilt-infunctionmethodsandpro-
ceduremethodsoncontainertypesareavailableinrulelanguagecomputationsandsequence
computations,cf. 13;inadditiontothemethodsdenedin6thatareonlyavailableinthe
rulelanguage.
16.1.1 FunctionMethodDenitionandCall
Functionmethodsare denedinexactlythesameway asafunctionis dened,justinside
thehostingclass. Theyhavethesamerequrirements,i.e. exactlyoneoutputvaluemustbe
returned,andtheymustbeside-eectfree,whichespeciallymeansthattheyarenotallowed
tochangetheattributesoftheirhostingtype.
FunctionMethodDenition
-
FunctionDenition
-
FunctionMethodCall
-
Variable
-
Variable
-
.
-
Attribute
-
.
-
Name
-
(
-
Expression
,
-
)
-
Asuchdenedfunctionmethodmaythenbecalledasanexpressionatomfromanywhere
intherulelanguagelewhereanexpressionisrequired;orevenfromthesequencecomputa-
tionswhereanexpressionisrequired. Thebuilt-infunctionmethodslistedin16.1arecalled
withthesamesyntax.
Insidethefunctionmethods,thespecialentitythisisavailable. Itallowstoaccessthe
attributesandmethodsofthetypethemethodiscontainedin. IncontrasttoJava,C++,
orC#wherethismaybeusedoptionallytodenotememberormethodaccess,theusageof
thisismandatoryinGrGen.NETtoaccesstheattributesofthetypeorcallthemethods
ofthetype.
16.1.2 ProcedureMethodDenitionAndCall
Proceduremethodsaredenedinexactlythesamewayasaprocedureisdened,justinside
thehostingclass.Theymayreturnanarbitrarynumberofreturnvalues,andarethusonly
callableasastatement. Theyareallowedtomanipulatethegraphandesp.theelementthey
arecontainedinasneededwhilebeingexecuted;soyouarefreetocallother procedures{
butincontrasttoglobalprocedures,youcannotincludeexecstatements.
ProcedureMethodDenition
-
ProcedureDenition
-
C# Create PDF from images Library to convert Jpeg, png images to
Best and professional C# image to PDF converter SDK C# Example: Convert More than Two Type Images to bmp")); images.Add(new Bitmap(Program.RootPath + "\\" 1
change pdf file to jpg file; conversion of pdf to jpg
VB.NET PDF Convert to Images SDK: Convert PDF to png, gif images
Best adobe PDF to image converter SDK for page As PDFPage = doc.GetPage(0) ' Convert the first page.ConvertToImage(ImageType.PNG, Program.RootPath + "Output.png
convert pdf file to jpg online; change pdf into jpg
16.1 Methods
189
string.length():int
string.startsWith():boolean
string.endsWith():boolean
string.indexOf(string[,int]):int
string.lastIndexOf(string[,int]):int
string.substring(int[,int]):string
string.replace(int, int, , string):string
string.toLower():string
string.toUpper():string
string.asArray(string):array<string>
set<T>.size():int
set<T>.empty():boolean
set<T>.peek(int):T
set<T>.asArray():array<T>
map<S,T>.size():int
map<S,T>.empty():boolean
map<S,T>.peek(int):S
map<S,T>.domain():set<S>
map<S,T>.range():set<T>
map<int,T>.asArray():array<T>
array<T>.size():int
array<T>.empty():boolean
array<T>.peek([int]):T
array<T>.indexOf(T[,int]):int
array<T>.lastIndexOf(T[,int]):int
array<T>.indexOfOrdered(T):int
array<T>.orderAscending():array<T>
array<T>.reverse():array<T>
array<T>.subarray(int, int):array<T>
array<T>.asDeque():deque<T>
array<T>.asSet():set<T>
array<T>.asMap():map<int,T>
array<string>.asString(string):string
array<T>.indexOfBy<attr>(typeof(attr)[,int]):int
array<T>.lastIndexOfBy<attr>(typeof(attr)[,int]):int
array<T>.indexOfOrderedBy<attr>(typeof(attr)):int
array<T>.orderAscendingBy<attr>():array<T>
deque<T>.size():int
deque<T>.empty():boolean
deque<T>.peek([int]):T
deque<T>.indexOf(T[,int]):int
deque<T>.lastIndexOf(T):int
deque<T>.subdeque(int, int):deque<T>
deque<T>.asArray():array<T>
deque<T>.asSet():set<T>
Table16.1: Functionmethodsataglance
VB.NET Create PDF from images Library to convert Jpeg, png images
Best and professional image to PDF converter SDK Components to batch convert PDF documents in Visual Basic images.Add(New REImage(Program.RootPath + "\\" 1
convert pdf into jpg format; best program to convert pdf to jpg
C# PDF Convert to Tiff SDK: Convert PDF to tiff images in C#.net
Best C#.NET PDF converter SDK for converting PDF to PDF documents to tiff format in Visual C# .NET program. Also supports convert PDF files to jpg, jpeg images.
pdf to jpeg; convert pdf to jpg converter
190
AdvancedModelling(Object-OrientedandGraph-OrientedProgramming)
ProcedureMethodCall
-
OutputAssignment
-
Variable
-
Variable
-
.
-
Attribute
-
.
-
Name
-
(
-
Expression
,
-
)
-
Asuchdenedproceduremaythenbecalledasastatementatomfromanywhereinthe
rulelanguagelewhereanattributeevaluation(/computation)isrequired;orevenfromthe
sequencecomputationswhereastatementisrequired.Thebuilt-inproceduremethodslisted
in16.2arecalledwiththesamesyntax.
Insidetheproceduremethod,thespecialentitythisisavailable. Itallowstoaccessthe
attributesandmethodsofthetypethemethodiscontainedin. IncontrasttoJava,C++,
orC#wherethismaybeusedoptionallytodenotememberormethodaccess,theusageof
thisismandatoryinGrGen.NETtoaccesstheattributesofthetypeorcallthemethods
ofthetype.
set<T>.add(T)
set<T>.rem(T)
set<T>.clear()
map<S,T>.add(S,T)
map<S,T>.rem(S)
map<S,T>.clear()
array<T>.add(T[,int])
array<T>.rem([int])
array<T>.clear()
deque<T>.add(T[,int])
deque<T>.rem([int])
deque<T>.clear()
Table16.2: Proceduremethodsataglance
C# PDF Convert to Images SDK: Convert PDF to png, gif images in C#
Best PDF converter SDK for Visual Studio .NET for PDFPage)doc.GetPage(0); // Convert the first page.ConvertToImage(ImageType.PNG, Program.RootPath + "Output.png
convert pdf document to jpg; batch convert pdf to jpg online
VB.NET Image: Visual Basic .NET Guide to Draw Text on Image in .
sure that you can create the best picture with you can freely use the method below in your program. powerful & profession imaging controls, PDF document, image
convert .pdf to .jpg online; convert pdf file to jpg on
16.1 Methods
191
EXAMPLE(93)
Inthefollowinglisting,wedeclarefunctionandaproceduremethodsinsideanodeclass,and
usethemfromarule. Pleasenotethemandatory y thisinthemethodstodenotemembers
andcallothermethods.
1
nodeclassN
2
{
3
i:int;
4
5
functionget_i():int
6
{
7
return(this.i);
8
}
9
procedureset_i(var val:int)
10
{
11
this.i =val;
12
return;
13
}
14
procedureinc_i(var val:int): (int)
15
{
16
this.set_i(this.get_i()+val );
17
return(this.i);
18
}
19
}
20
21
rulefoo :(int)
22
{
23
n:N;
24
modify{
25
defvari:int;
26
eval{
27
n.set_i(41);
28
n.inc_i(1);
29
yieldi = n.get_i();
30
}
31
return(i); // exeutingfoowillreturn42
32
}
33
}
C# Create PDF Library SDK to convert PDF from other file formats
Best C#.NET component to create searchable PDF document from Microsoft Office String outputFile = Program.RootPath + "\\" output.pdf"; // Create a
convert pdf to jpg for online; best way to convert pdf to jpg
VB.NET Create PDF Library SDK to convert PDF from other file
with Visual Basic .NET class and able to create PDF in both .NET WinForms and ASP.NET program. Best VB.NET component to convert Microsoft Office Word
convert pdf file to jpg file; reader convert pdf to jpg
192
AdvancedModelling(Object-OrientedandGraph-OrientedProgramming)
EXAMPLE(94)
Thefollowinglistinghighlightstheeectofdynamicdispatch(theheartandsoulofobject-
orientedprogramming): themethodnallycalleddependsnotsimplyonthestatictypewe
knowforsuretheobjectisaninstanceof,butontherealdynamictypeoftheobject,thatit
wascreatedwith.Pleasenotethatinrealityyouusethislanguagedevicetoachievethesame
behaviour asseenfromtheoutwardofobjectsofdierenttypes,butimplementedinternally
consistent regardingthe e exact type,takingallof its members into account (including the
onesunknowntoparenttypes).
1
nodeclassN
2
{
3
functionget():int
4
{
5
return(0);
6
}
7
}
8
9
nodeclassNNextendsN
10
{
11
functionget():int
12
{
13
return(1);
14
}
15
}
16
17
rulefoo :(int)
18
{
19
n:N;//staticallydeclaredN, maymatchdynamicallytonode oftypeNN
20
modify{
21
defvari:int;
22
eval{
23
yieldi = n.get();
24
}
25
return(i); // exeutingfoowillreturn0 iff nwasboundtonode oftypeN, but1iff
n wasbound to nodeoftypeNN
26
}
27
}
16.2 Packages
Packagesallowyoutoseparateaprojectintonamespacesthatshieldtheircontentfromname
clasheswhengettingused(formodels)orincluded(foractions)together. Theyincursome
non-negligiblenotationaloverheadaseveryusageofanamefromapackageoutsideofthat
packagemust beprexedwiththepackagename(intheformpackagename::name),sowe
recommend to use themonly y whenneeded. . This s holds s esp. . as s we e expect that a typical
project will l be limitedto an algorithmic kernel writtenby y a single programmer who has
everythingundercontrolandcanthuseasilypreventnameclashes.
16.2 Packages
193
16.2.1 PackageDenitionintheModel
PackageDenitionModel
-
package
-
IdentDecl
-
f
-
ClassDeclaration
-
EnumDeclaration
-
g
-
Apackagedenitioninthemodelissimilartoamodeldenitionassuch,justreducedinits
content. ItconsistsofClassDeclarations,deningnodeoredgetypes,orEnumDeclarations
dening enum types. . The e AdvancedModelDeclarations s allowed in the root model are not
availableinsideapackage,neithercanothermodelsbeincludedinsideapackagewithusing.
Packagedenitionscannot benested.
PackageUsageModel
-
Ident
-
::
-
Ident
-
Ineverycontextwhereanodetype,anedgetypeoranenumtypecanbereferenced,by
notingdownitsdeclaredidentier,canalsoatypefromapackagebereferenced,bynoting
downitspackageasaprex.Thepackageprexmaybeomittedinsidethepackageforother
entities fromthesamepackage. . Butonlyforthem,outsidethat t packageyoumustalways
usethepackageprexedformforreferencingidentiersfromthepackage.
EXAMPLE(95)
Typesfromamodeldenedlikethis:
1
packageFoo {
2
nodeclassN {
3
attr: Lol;
4
}
5
enumLol {
6
Bla,
7
Blub
8
}
9
}
10
11
packageBar {
12
nodeclassN {
13
attr: Foo::Lol;
14
}
15
}
Canbeusedlikethis:
1
rule r(varinp: Foo::Lol) {
2
x: Foo::N-->y :Bar::N;
3
if{ x.attr==Foo::Lol::Bla; }
4
5
modify{
6
eval{add(Foo::N);}
7
eval{ y.attr =Foo::Lol::Blub; }
8
}
9
}
194
AdvancedModelling(Object-OrientedandGraph-OrientedProgramming)
16.2.2 PackageDenitionintheActions
PackageDenitionAction
-
package
-
IdentDecl
-
f
-
ActionDeclaration
-
SubpatternDeclaration
-
RewriteSequenceDenition
-
FunctionDenition
-
ProcedureDenition
-
FilterFunctionDenition
-
g
-
Apackagedenitionintheactionsissimilartoarulesetdenitionassuch,justreduced
initscontent. ItconsistsofActionDeclarations,deningrulesandtests,orSubpatternDec-
larationstobeusedfromtheactions,orFilterFunctionDenitions,forlteringthematches
ofthe actions. . It t furthermoreconsistsofFunctionDenitions andProcedureDenitions,or
RewriteSequenceDenitions. Theleheaderconstructsforusingmodels,includingotherac-
tions,ordeclaringglobalvariablesarenot availableinsideapackage. . Neither r canpackage
denitionsbenested.
ThepackagesMath,File,andTimearebuilt-in,theirfunctions andprocedures canbe
useddirectly(see6.8and14.3fortheircontent).
PackageUsageActions
-
Ident
-
::
-
Ident
-
Ineverycontextwherearule,atest,asubpatterntype,alterfunction,afunction,a
procedure,orasequencecanbereferenced,bynotingdownitsdeclaredidentier,canalso
anentityfromapackagebereferenced,bynotingdownitspackageasaprex. Thepackage
prexmaybeomittedinsidethepackageforotherentitiesfromthesamepackage.Butonly
forthem,outsidethatpackageyoumustalwaysusethepackageprexedformforreferencing
identiersfromthepackage.
Thepackages inthe actionsare declared d withthesame syntax x as thepackages in n the
model, but t are otherwise separate. . You u cannot extend amodelpackage withanactions
package,or vice versa. . Apackagewitha a givenname canonlybetied once,eitherin the
modelortheactions.
16.2 Packages
195
EXAMPLE(96)
Theexamplehighlightshowactionpackagescanbeused.
1
packageFoo {
2
patternP {
3
x:Node -e:Edge-> x;
4
5
modify {
6
delete(e);
7
}
8
}
9
10
ruler {
11
p:P();
12
13
modify {
14
p();
15
eval{ Bar::proc(true); }
16
}
17
}
18
19
filterf<r>{
20
return;
21
}
22
}
23
24
packageBar {
25
ruler {
26
x:Node -e:Edge-> x;
27
if{ func();}
28
29
modify {
30
delete(e);
31
exec(Foo::r\Foo::f);
32
}
33
}\ auto
34
35
functionfunc:boolean{
36
return(true);
37
}
38
39
procedureproc(varb:boolean) {
40
return;
41
}
42
}
43
44
ruler2{
45
if{ Bar::func(); }
46
p:Foo::P();
47
48
modify{
49
p();
50
}
51
}
52
53
sequence s2 {
54
Foo::r()\Foo::f ;>Bar::r\auto;> {Bar::proc(Bar::func());}
55
}
196
AdvancedModelling(Object-OrientedandGraph-OrientedProgramming)
16.3 GraphNesting
Graphnestingispossiblewithnodesoredgesofagraphbearingattributesofgraphtype(cf.
14).Theycanthenbelledwithothergraphs,employingtheoperationsin14.3.
Attributesofgraphtypeareopaquetotheprocessingofthehostgraphcontainingthem;
theironlydirectusageiscomparison,i.e.isomorphycheckingagainstothergraphs,asneeded
forstatespaceenumeration(cf. 19.7),inthiscaseonlyimmutablesubgraphsarestored.
ExtendedControl
-
in
-
GraphVariable
-
NodeOrEdge
-
.
-
Attribute
-
f
-
RewriteSequence
-
g
-
Buttheycanbeopenedupandmademodiablebyswitchingthelocationofprocessing
withthe in n g g { seq } } sequence. . Inside e the braces s is s the host graph h switched to g, the
sequenceseqisexecutedinthehostgraphswitchedto,allqueriesandupdatesarecarried
outonthenewgraph;afterexecutingtheconstructtheoldgraphthatwaspreviouslyused
ismadethecurrenthostgraphagain.
Rule
-
GraphVariable
-
.
-
RuleIdent
-
(
-
Variable
,
-
)
-
Therulesarealwaysappliedonthecurrenthostgraphwithoutanyabilitytoswitchto
a subgraph; switchingthelocation ofprocessingis onlyavailableinthesequences. . Buta
simpliedandmorelightweightversionofthefullswitchisavailableforsinglerulecallswith
g.r;soamethodcallintheplainsequences(abovethesequencecomputations)denotesin
factatemporarysubgraphswitch.Thesyntaxofruleapplicationisextendedbythegrammar
ruleabovetoallowforthisis.
Theinformationhiding shownbythegraphattributesiscomparabletotheinformation
hidingshownbytheobjectsinobject-orientedprogramming,theretheattributes butespe-
ciallytheneighbouringelementsareonly knowntothecontainingobject andaccessibleto
themethodsoftheobject. Ingraph-orientedprogramming g aretheattributesbutespecially
the neighboringelements knownto the containinggraph, the connecting topology isopen
forpatternmatching. ThiscrucialdierencealsodenesthemainbenetcomparedtoOO,
removingitwouldmeantorevertbacktoOO.Butthisopennessmightnotbeneededalways
forallparts.Whenbuildingalargesystem,youtypicallyonlyneedacertainlayer tobeac-
cessibleatatime.Youmayusegraphattributesandnestedgraphinthiscase,utilizingopen
graph-orientedprogrammingforthepartsyouneedtoworkgloballywithpatternmatching
atatime,andclosedobject-orientedprogrammingforpartsyouonlyneedtoaccesslocally,
decoupledbyexplicitmove-to-subgraphandreturn-to-subgraphsteps.
You may y model l containment t withedges s denoting g a containment type pointing to the
containedpartsinsteadofattributesofsubgraphtypewhenthepatternmatcherneedsoverall
accesstothegraph,buttherearestillsomecontainmentornestingrelationshipsinplace.You
canthenstillbenetfromahierarchicalstructureindebugging,utilizingthebuilt-innesting
for visualizationcapabilitiesofGrGen.NET(cf. 21.1,the e graphs nestedinattributesare
trulyopaqueandinvisible,onlywhenprocessingswitchestothemaretheydisplayedinstead
oftheircontaininghostgraph).
Documents you may be interested
Documents you may be interested