Translate Model class' storage to C++.
Some code copied from xs-model branch.
Also:
* Generate ::Ref classes programatically.
* Add separate __REGISTER_CLASS macro
(for use where forward declaration won't work, i.e. typedefs)
This commit is contained in:
59
xs/xsp/StringMap.xsp
Normal file
59
xs/xsp/StringMap.xsp
Normal file
@@ -0,0 +1,59 @@
|
||||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "StringMap.hpp"
|
||||
#include "perlglue.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::StringMap} class StringMap {
|
||||
std::string FETCH(std::string key)
|
||||
%code%{
|
||||
StringMap::iterator i = THIS->find(key);
|
||||
if (i == THIS->end()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = i->second;
|
||||
%};
|
||||
|
||||
void STORE(std::string key, std::string val)
|
||||
%code%{ (*THIS)[key] = val; %};
|
||||
|
||||
void DELETE(std::string key)
|
||||
%code%{ THIS->erase(key); %};
|
||||
|
||||
void CLEAR()
|
||||
%code%{ THIS->clear(); %};
|
||||
|
||||
bool EXISTS(std::string key)
|
||||
%code%{ RETVAL = (THIS->find(key) != THIS->end()); %};
|
||||
|
||||
std::string FIRSTKEY()
|
||||
%code%{
|
||||
StringMap::iterator i = THIS->begin();
|
||||
if (i == THIS->end()) {
|
||||
XSRETURN_UNDEF;
|
||||
} else {
|
||||
RETVAL = i->first;
|
||||
}
|
||||
%};
|
||||
|
||||
std::string NEXTKEY(std::string lastkey)
|
||||
%code%{
|
||||
StringMap::iterator i = THIS->find(lastkey);
|
||||
if (i == THIS->end()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
++i;
|
||||
if (i == THIS->end()) {
|
||||
XSRETURN_UNDEF;
|
||||
} else {
|
||||
RETVAL = i->first;
|
||||
}
|
||||
%};
|
||||
|
||||
bool SCALAR()
|
||||
%code%{ RETVAL = !THIS->empty(); %};
|
||||
};
|
||||
Reference in New Issue
Block a user