NAME
Stlgen - Create "Standard Template Library" (STL) C++ type containers but generate code in other languages.
VERSION
Version 0.012
SYNOPSIS
Stlgen is based off the Standard Template Library (STL) for C++ here:
http://www.cplusplus.com/reference/stl/
The difference is that Stlgen will generate instances of STL templates in a different language. The default language is c.
This example below uses Stlgen to generate list_uint.(c/h) files which will implement a linked list container coded in the c language.
#!/usr/bin/perl -w
use Stlgen;
my $inst = Stlgen->New(
Template=>'list',
Instancename => 'uint',
payload => [
{name=>'uint', type=>'unsigned int', dumper=>'printf("\t\tuint = %u\n", currelement->uint);'},
],
);
$inst->Instantiate();
You could use these files in a main.c program like this:
#include <stdio.h>
#include "list_uint.h"
int main (void) {
struct list_uint_list *mylist;
mylist = list_uint_constructor();
list_uint_push_back(mylist, 21);
list_uint_push_back(mylist, 99);
list_uint_push_back(mylist, 33);
list_uint_push_back(mylist, 34);
list_uint_push_back(mylist, 67);
list_uint_push_back(mylist, 12);
list_uint_push_back(mylist, 28);
list_uint_push_back(mylist, 55);
list_uint_push_back(mylist, 76);
list_uint_sort(mylist);
printf("\n\n\nThis is the sorted list\n");
list_uint_list_dumper(mylist);
return 0;
}
The above c program currently works and produces the following output when you compile and execute it:
This is the sorted list
// list at address 140644360{
'beforefirst' marker:
// element at address 8621018
prev = 0
next = 8621088
uint = 0
user elements:
// element at address 8621088
prev = 8621018
next = 8621038
uint = 12
// element at address 8621038
prev = 8621088
next = 8621098
uint = 21
// element at address 8621098
prev = 8621038
next = 8621058
uint = 28
// element at address 8621058
prev = 8621098
next = 8621068
uint = 33
// element at address 8621068
prev = 8621058
next = 86210a8
uint = 34
// element at address 86210a8
prev = 8621068
next = 8621078
uint = 55
// element at address 8621078
prev = 86210a8
next = 86210b8
uint = 67
// element at address 86210b8
prev = 8621078
next = 8621048
uint = 76
// element at address 8621048
prev = 86210b8
next = 8621028
uint = 99
'afterlast' marker:
// element at address 8621028
prev = 8621048
next = 0
uint = 0
Note: this is a pre-alpha version. Currently the only STL container implemented is the linked list. And that hasn't been tested very well yet. The "push", "pop", "size", "sort", and "dumper" functions are known to work.
SUBROUTINES/METHODS
New
Create a Stlgen object.
FindTemplate
Given all the configuration info we know, find the template that the user wants to use.
Instantiate
Instantiate a template based on a particular type.
function2
AUTHOR
Greg London, <email at greglondon.com>
BUGS
Please report any bugs or feature requests to bug-stlgen at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Stlgen. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Stlgen
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2010 Greg London.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.