Skip to content

Commit

Permalink
Merge pull request #12 from pfernique/master
Browse files Browse the repository at this point in the history
Add vector
  • Loading branch information
pfernique committed Mar 12, 2017
2 parents eea0924 + 1f773ac commit f3bdfdf
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 372 deletions.
149 changes: 7 additions & 142 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,150 +1,15 @@
# -*-python-*-

import os
from SCons.Errors import EnvironmentError

env = Environment(tools = ['toolchain'])

VECTORS = ['size_t',
'int',
'double',
'std::string']
VariantDir(os.path.join('build', 'src'), 'src')
VariantDir(os.path.join('build', 'test'), 'test')

SETS = { 'less': ['size_t',
'int',
'double',
'std::string']}
SConscript(os.path.join('build', 'src', 'cpp', 'SConscript'), exports="env")
SConscript(os.path.join('build', 'src', 'py', 'SConscript'), exports="env")
SConscript(os.path.join('build', 'test', 'SConscript'), exports="env")
SConscript(os.path.join('conda', 'SConscript'), exports="env")

HEADER = """\
#ifndef STATISKIT_STL_H
#define STATISKIT_STL_H
#include <vector>
#include <set>
#include <string>
#if defined WIN32 || defined _WIN32 || defined __CYGWIN__
#ifdef LIBSTATISKIT_STL
#ifdef __GNUC__
#define STATISKIT_STL_API __attribute__ ((dllexport))
#else
#define STATISKIT_STL_API __declspec(dllexport)
#endif
#else
#ifdef __GNUC__
#define STATISKIT_STL_API __attribute__ ((dllimport))
#else
#define STATISKIT_STL_API __declspec(dllimport)
#endif
#endif
#else
#if __GNUC__ >= 4
#define STATISKIT_STL_API __attribute__ ((visibility ("default")))
#else
#define STATISKIT_STL_API
#endif
#endif
namespace statiskit
{
namespace stl
{
template<class T>
class Generator
{
public:
Generator(const T& iterable)
{
_cur = iterable.cbegin();
_end = iterable.cend();
}
virtual ~Generator()
{}
Generator(const Generator< T >& generator)
{
_cur = generator._cur;
_end = generator._end;
}
bool is_valid() const
{ return _cur != _end; }
Generator< T >& operator++()
{
++_cur;
return *this;
}
typename T::value_type value() const
{ return *_cur; }
protected:
typename T::const_iterator _cur;
typename T::const_iterator _end;
};
typedef std::string String;
"""

def capitalize(T):
return ''.join([t.capitalize() for t in T.replace('std::', '').replace('_', ' ').split()])

with open('src/cpp/STL.h', 'w') as filehandler:
filehandler.write(HEADER)
filehandler.write('\n')
for T in VECTORS:
filehandler.write('\t\ttypedef std::vector< ' + T + ' > Vector' + capitalize(T) +';\n')
filehandler.write('\n')
for sort in SETS:
for T in SETS[sort]:
SET = 'Set' + sort.capitalize() + capitalize(T)
filehandler.write('\t\ttypedef std::set< ' + T + ', std::' + sort + '< ' + T + ' >, std::allocator< ' + T + ' > > ' + SET + ';\n')
GENERATOR = SET + 'Generator'
filehandler.write('\t\ttypedef Generator< ' + SET + ' > ' + GENERATOR + ';\n')
filehandler.write('\t\tSTATISKIT_STL_API ' + GENERATOR + ' generator(const ' + SET + '& iterable);\n')
filehandler.write('\t\tSTATISKIT_STL_API bool insert(' + SET + '& iterable, const ' + T + '& value);\n')
filehandler.write('\n')
filehandler.write('\t}\n}\n\n\n#endif')

with open('src/cpp/STL.cpp', 'w') as filehandler:
filehandler.write('#include "STL.h"\n\nnamespace statiskit\n{\n\tnamespace stl\n\t{\n')
for sort in SETS:
for T in SETS[sort]:
SET = 'Set' + sort.capitalize() + capitalize(T)
GENERATOR = SET + 'Generator'
filehandler.write('\t\t' + GENERATOR +' generator(const ' + SET + '& iterable)\n')
filehandler.write('\t\t{ return ' + GENERATOR + '(iterable); }\n\n')
filehandler.write('\t\tbool insert(' + SET + '& iterable, const ' + T + '& value)\n')
filehandler.write('\t\t{ return iterable.insert(value).second; }\n\n')
filehandler.write('\t}\n}')

VariantDir('build', 'src')
try:
SConscript(os.path.join('build', 'cpp', 'SConscript'), exports="env")
except EnvironmentError:
pass
except Exception:
raise
try:
SConscript(os.path.join('build', 'py', 'SConscript'), exports="env")
except EnvironmentError:
pass
except Exception:
raise
try:
SConscript(os.path.join('test', 'SConscript'), exports="env")
except EnvironmentError:
pass
except Exception:
raise
try:
SConscript(os.path.join('conda', 'SConscript'), exports="env")
except EnvironmentError:
pass
except Exception:
raise
Default("install")
Default("install")
41 changes: 21 additions & 20 deletions conda/SConscript
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
# -*-python-*-

Import("env")
from SCons.Errors import EnvironmentError

conda_env = env.Clone(tools = ['conda'])
try:
Import("env")

sources = conda_env.Glob('*')
conda_env = env.Clone(tools = ['conda'])

# Exclude here all Conda recipes that must not be built
exclude = """
""".split()
sources = conda_env.Glob('*')

sources = [source for source in sources if not source.name in exclude]
exclude = """
""".split()

targets = conda_env.CondaPackages(sources)
Alias("conda-build", targets)
sources = [source for source in sources if not source.name in exclude]

# targets = conda_env.AnacondaUpload(sources)
# Alias("anaconda-upload", targets)
targets = conda_env.CondaPackages(sources)
Alias("conda-build", targets)

# Exclude here all Conda recipes that must not be installed
# in the current Environment. These recipes that must not be
# installed corresponds to all recipes for which code source
# is located in the current repository.
exclude = """
""".split()
exclude = """
""".split()

sources = [source for source in sources if not source.name in exclude]
sources = [source for source in sources if not source.name in exclude]

targets = conda_env.CondaEnvironment(sources)
Alias("conda-install", targets)
targets = conda_env.CondaEnvironment(sources)
Alias("conda-install", targets)
except EnvironmentError:
Alias("conda-build", [])
Alias("conda-install", [])
pass
except Exception:
raise
4 changes: 2 additions & 2 deletions src/cpp/AutoWIG.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def controller(asg):
for cls in asg['class ::std::default_delete'].specializations():
cls.boost_python_export = False
for mtd in asg['::statiskit::stl::String'].qualified_type.desugared_type.unqualified_type.methods():
if mtd.localname == 'compare':
mtd.boost_python_export = False
#if mtd.localname in ['substr', 'compare']:
mtd.boost_python_export = False
return asg

def generator(asg, module, decorator):
Expand Down

0 comments on commit f3bdfdf

Please sign in to comment.