Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Niflib
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Grant Kim
Niflib
Commits
167f47c7
Commit
167f47c7
authored
18 years ago
by
wz
Browse files
Options
Downloads
Patches
Plain Diff
Added Py++ project to contrib/niflib folder.
parent
36b8cbfa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
contrib/niflib/pyplusplus/build_header.py
+91
-0
91 additions, 0 deletions
contrib/niflib/pyplusplus/build_header.py
contrib/niflib/pyplusplus/build_wrapper.py
+104
-0
104 additions, 0 deletions
contrib/niflib/pyplusplus/build_wrapper.py
with
195 additions
and
0 deletions
contrib/niflib/pyplusplus/build_header.py
0 → 100644
+
91
−
0
View file @
167f47c7
######
## Generate Py++ inclusion header
######
import
wrapper_config
# Set the paths to be searched for header files
header_paths
=
[
wrapper_config
.
niflib_path
+
"
/include
"
,
wrapper_config
.
niflib_path
+
"
/include/gen
"
,
wrapper_config
.
niflib_path
+
"
/include/obj
"
]
# Set explicit includes
header_include
=
[
wrapper_config
.
niflib_path
+
"
/include/niflib.h
"
,
wrapper_config
.
niflib_path
+
"
/include/Ref.h
"
,
wrapper_config
.
niflib_path
+
"
/include/Type.h
"
,
wrapper_config
.
niflib_path
+
"
/include/nif_math.h
"
,
wrapper_config
.
niflib_path
+
"
/include/Key.h
"
,
wrapper_config
.
niflib_path
+
"
/include/nif_basic_types.h
"
]
# Set the regexps for file exclusion
header_exclude
=
[
"
niflib/include/[a-zA-Z\.\_\-]+\.h
"
]
####
import
os
,
re
def
hasExtension
(
file
,
ext
):
fext
=
file
.
rsplit
(
'
.
'
,
-
1
)[
-
1
]
return
(
fext
in
ext
)
header
=
[]
pattern
=
"
|
"
.
join
(
header_exclude
)
p
=
re
.
compile
(
pattern
)
for
path
in
header_paths
:
dir_files
=
os
.
listdir
(
path
)
for
file
in
dir_files
:
m
=
p
.
match
(
path
+
'
/
'
+
file
)
if
m
:
continue
if
hasExtension
(
file
,
[
'
h
'
,
'
hpp
'
]):
header_include
.
append
(
path
+
'
/
'
+
file
)
for
file
in
header_include
:
header
.
append
(
"
#include
\"
%s
\"\n
"
%
file
)
#header.append("using namespace Niflib;\n\n");
header
.
append
(
"
\n
"
);
header
.
append
(
"
/* This namespace is not going to be exported */
\n
"
)
header
.
append
(
"
namespace NoExport {
\n\n
"
)
header
.
append
(
"
/* Auxiliary function for template export */
\n
"
)
header
.
append
(
"
inline void export_obj_templates() {
\n
"
)
header
.
append
(
"
Niflib::NiObjectRef CastObj;
\n\n
"
)
NiObjects
=
[]
for
obj
in
os
.
listdir
(
wrapper_config
.
niflib_path
+
"
/include/obj
"
):
obj_
=
obj
.
split
(
'
.
'
,
2
)[
0
]
if
hasExtension
(
obj
,
'
h
'
)
and
not
obj_
in
NiObjects
:
NiObjects
.
append
(
obj_
)
for
obj
in
NiObjects
:
header
.
append
(
"
/* Object %s */
\n
"
%
obj
)
#header.append(" typedef Niflib::Ref<Niflib::%s> %sRef;\n" % (obj, obj))
#header.append(" sizeof(%sRef);\n" % obj)
header
.
append
(
"
sizeof(Niflib::Ref<Niflib::%s>);
\n
"
%
obj
)
header
.
append
(
"
Niflib::DynamicCast<Niflib::%s>(CastObj);
\n
"
%
obj
)
header
.
append
(
"
Niflib::StaticCast <Niflib::%s>(CastObj);
\n
"
%
obj
)
header
.
append
(
"
\n
"
)
header
.
append
(
"
/* Internal Containers */
\n
"
)
for
int_cont
in
wrapper_config
.
internal_containers
:
header
.
append
(
"
sizeof(%s);
\n
"
%
int_cont
)
header
.
append
(
"
\n
"
)
header
.
append
(
"
}
\n\n
"
)
header
.
append
(
"
}
\n\n
"
)
headerfile
=
open
(
"
pyNiflib.h
"
,
"
w
"
)
headerfile
.
writelines
(
header
)
headerfile
.
close
()
project_files
=
[
r
"
pyNiflib.h
"
]
for
hfile
in
header_include
:
basename
=
hfile
.
rsplit
(
"
.
"
,
2
)[
0
]
#project_files.append(r"%s.cpp" % basename)
This diff is collapsed.
Click to expand it.
contrib/niflib/pyplusplus/build_wrapper.py
0 → 100644
+
104
−
0
View file @
167f47c7
######
## Build boost::python wrapper file
######
import
os
,
re
from
pyplusplus
import
module_builder
from
pygccxml
import
declarations
import
wrapper_config
# The Niflib license
niflib_license
=
\
"""
/*
Copyright (c) 2005, NIF File Format Library and Tools
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the NIF File Format Library and Tools
project nor the names of its contributors may be used to endorse
or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"
AS IS
"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
"""
####
# Function to get the type name of a template function
def
TypeName
(
decl_string
):
return
declarations
.
templates
.
args
(
decl_string
)[
0
].
rsplit
(
'
::
'
,
2
)[
-
1
]
# Function to rename the Cast<T> functions
def
rename_casts
(
cast
):
cast
.
rename
(
cast
.
name
+
'
To
'
+
TypeName
(
cast
.
decl_string
)
)
cast
.
name
=
cast
.
demangled_name
# Function to rename the Ref<T> functions
def
rename_refs
(
ref
):
ref
.
rename
(
TypeName
(
ref
.
decl_string
)
+
"
Ref
"
)
####
# Creating an instance of class that will help you to expose your declarations
mb
=
module_builder
.
module_builder_t
(
[
r
"
pyNiflib.h
"
]
,
include_paths
=
[
wrapper_config
.
niflib_path
+
'
/include
'
,
wrapper_config
.
niflib_path
+
'
/include/gen
'
,
wrapper_config
.
niflib_path
+
'
/include/obj
'
]
,
indexing_suite_version
=
2
)
# Set the max. number of template arguments
mb
.
BOOST_PYTHON_MAX_ARITY
=
20
# Rename the Ref<T> templates
refs
=
mb
.
classes
(
lambda
decl
:
(
decl
.
name
.
startswith
(
'
Ref<
'
)
)
)
map
(
rename_refs
,
refs
)
# Rename the DynamicCast<T> and StaticCast<T> templates
casts
=
mb
.
free_functions
(
lambda
decl
:
(
decl
.
name
==
'
DynamicCast
'
or
decl
.
name
==
'
StaticCast
'
)
)
map
(
rename_casts
,
casts
)
# Get all operators
mb
.
member_operators
().
exclude
()
# Optimize the queries
mb
.
run_query_optimizer
()
# Exclude everything
mb
.
global_ns
.
exclude
()
# Include the main Niflib namespace
mb
.
namespace
(
'
Niflib
'
).
include
()
# Create code creator. After this step you should not modify/customize declarations.
mb
.
build_code_creator
(
module_name
=
'
pyNiflib
'
)
# Set the Niflib license for the output
mb
.
code_creator
.
license
=
niflib_license
# Well, don't you want to see what is going on?
mb
.
print_declarations
(
mb
.
namespace
(
'
Niflib
'
))
# Writing code to file.
mb
.
write_module
(
'
./pyNiflib.cpp
'
)
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