Skip to content

Commit

Permalink
Merge pull request #1086 from dictoon/master
Browse files Browse the repository at this point in the history
Refactorings
  • Loading branch information
dictoon authored Sep 10, 2016
2 parents 6d0b1ce + d9de986 commit e842a3e
Show file tree
Hide file tree
Showing 162 changed files with 538 additions and 262 deletions.
96 changes: 96 additions & 0 deletions scripts/sortincludes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/python

#
# This source file is part of appleseed.
# Visit http://appleseedhq.net/ for additional information and resources.
#
# This software is released under the MIT license.
#
# Copyright (c) 2016 Francois Beaune, The appleseedhq Organization
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

import argparse
import os
import sys


#--------------------------------------------------------------------------------------------------
# Processing code.
#--------------------------------------------------------------------------------------------------

def process_file(filepath):
print("processing {0}...".format(filepath))

with open(filepath) as f:
lines = f.readlines()

section_begin = -1

for index in range(len(lines)):
line = lines[index]

if section_begin == -1 and line.startswith("#include"):
section_begin = index

if section_begin != -1 and line in ["\n", "\r\n"]:
if all(clause.startswith("#include") for clause in lines[section_begin:index]):
lines[section_begin:index] = sorted(lines[section_begin:index])
section_begin = -1

with open(filepath + ".processed", "wt") as f:
for line in lines:
f.write(line)

os.remove(filepath)
os.rename(filepath + ".processed", filepath)

def process_recursively():
for dirpath, dirnames, filenames in os.walk("."):
for filename in filenames:
ext = os.path.splitext(filename)[1]
if ext == ".h" or ext == ".cpp":
process_file(os.path.join(dirpath, filename))


#--------------------------------------------------------------------------------------------------
# Entry point.
#--------------------------------------------------------------------------------------------------

def main():
parser = argparse.ArgumentParser(description="sort #include clauses in c++ source code.")
parser.add_argument("-r", "--recursive", action='store_true', dest='recursive',
help="process all files in the specified directory and all its subdirectories")
parser.add_argument("filepath", nargs="?", help="file to process")
args = parser.parse_args()

if args.filepath:
if args.recursive:
print("cannot simultaneously specify a file path and use the --recursive flag.")
sys.exit(1)
print(args.filepath)
else:
if not args.recursive:
print("either a file path or the --recursive flag must be specified.")
sys.exit(1)
process_recursively()

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion src/appleseed.python/bindcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

// appleseed.foundation headers.
#include "foundation/image/colorspace.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"

// Standard headers.
#include <cstddef>
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed.python/bindobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "renderer/api/scene.h"

// appleseed.foundation headers.
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"
#include "foundation/utility/searchpaths.h"

namespace bpy = boost::python;
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed.python/bindshadergroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

// appleseed.foundation headers.
#include "foundation/utility/autoreleaseptr.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"
#include "foundation/utility/searchpaths.h"

// Standard headers.
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed.python/dict2dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// appleseed.foundation headers.
#include "foundation/math/vector.h"
#include "foundation/utility/containers/dictionary.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"
#include "foundation/utility/foreach.h"
#include "foundation/utility/iostreamop.h"
#include "foundation/utility/string.h"
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed.python/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

// appleseed.foundation headers.
#include "foundation/utility/containers/dictionary.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"

namespace detail
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

// appleseed.foundation headers.
#include "foundation/utility/containers/dictionary.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"

// Qt headers.
#include <QPushButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

// appleseed.foundation headers.
#include "foundation/platform/compiler.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"

// Qt headers.
#include <QFrame>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

// appleseed.foundation headers.
#include "foundation/utility/containers/dictionary.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"

// Standard headers.
#include <cstddef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "mainwindow/project/entityeditorformfactorybase.h"

// appleseed.foundation headers.
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"

// Standard headers.
#include <string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

// appleseed.foundation headers.
#include "foundation/math/vector.h"
#include "foundation/utility/api/apistring.h"
#include "foundation/utility/string.h"

// Qt headers.
#include <QComboBox>
Expand Down Expand Up @@ -159,16 +161,12 @@ namespace
}
}

string print_entity(const char* label, const Entity* entity)
string print_entity(const char* prefix, const Entity* entity)
{
stringstream sstr;
sstr << label;

if (entity)
sstr << "\"" << entity->get_path() << "\" (#" << entity->get_uid() << ")";
else sstr << "n/a";

return sstr.str();
return
entity
? format("{0}\"{1}\" (#{2})", prefix, entity->get_path(), entity->get_uid())
: format("{0}n/a", prefix);
}

const Entity* get_picked_entity(
Expand Down
17 changes: 14 additions & 3 deletions src/appleseed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,20 @@ source_group ("foundation\\platform" FILES
${foundation_platform_sources}
)

set (foundation_utility_api_sources
foundation/utility/api/apiarray.h
foundation/utility/api/apistring.cpp
foundation/utility/api/apistring.h
foundation/utility/api/specializedapiarrays.cpp
foundation/utility/api/specializedapiarrays.h
)
list (APPEND appleseed_sources
${foundation_utility_api_sources}
)
source_group ("foundation\\utility\\api" FILES
${foundation_utility_api_sources}
)

set (foundation_utility_benchmark_sources
foundation/utility/benchmark/benchmarkaggregator.cpp
foundation/utility/benchmark/benchmarkaggregator.h
Expand Down Expand Up @@ -577,12 +591,9 @@ source_group ("foundation\\utility\\commandlineparser" FILES
)

set (foundation_utility_containers_sources
foundation/utility/containers/array.h
foundation/utility/containers/dictionary.cpp
foundation/utility/containers/dictionary.h
foundation/utility/containers/hashtable.h
foundation/utility/containers/specializedarrays.cpp
foundation/utility/containers/specializedarrays.h
)
list (APPEND appleseed_sources
${foundation_utility_containers_sources}
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed/foundation/meta/tests/test_iostreamop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// appleseed.foundation headers.
#include "foundation/math/aabb.h"
#include "foundation/math/vector.h"
#include "foundation/utility/containers/specializedarrays.h"
#include "foundation/utility/api/specializedapiarrays.h"
#include "foundation/utility/iostreamop.h"
#include "foundation/utility/test.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
// THE SOFTWARE.
//

#ifndef APPLESEED_FOUNDATION_UTILITY_CONTAINERS_ARRAY_H
#define APPLESEED_FOUNDATION_UTILITY_CONTAINERS_ARRAY_H
#ifndef APPLESEED_FOUNDATION_UTILITY_API_APIARRAY_H
#define APPLESEED_FOUNDATION_UTILITY_API_APIARRAY_H

// appleseed.main headers.
#include "main/dllsymbol.h"
Expand All @@ -43,12 +43,10 @@ namespace foundation
{

//
// An array of elements of a given type with minimalistic functionalities.
//
// The array can be passed safely across DLL boundaries.
// A minimalist array class that can safely cross DLL boundaries.
//

#define APPLESEED_DECLARE_ARRAY(ArrayName, ArrayType) \
#define APPLESEED_DECLARE_APIARRAY(ArrayName, ArrayType) \
class APPLESEED_DLLSYMBOL ArrayName \
{ \
public: \
Expand Down Expand Up @@ -106,7 +104,7 @@ namespace foundation
Impl* impl; \
}

#define APPLESEED_DEFINE_ARRAY(ArrayName) \
#define APPLESEED_DEFINE_APIARRAY(ArrayName) \
struct ArrayName::Impl \
: public std::vector<value_type> \
{ \
Expand Down Expand Up @@ -225,4 +223,4 @@ U array_vector(const V& v)

} // namespace foundation

#endif // !APPLESEED_FOUNDATION_UTILITY_CONTAINERS_ARRAY_H
#endif // !APPLESEED_FOUNDATION_UTILITY_API_APIARRAY_H
55 changes: 55 additions & 0 deletions src/appleseed/foundation/utility/api/apistring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2016 Francois Beaune, The appleseedhq Organization
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// Interface header.
#include "apistring.h"

namespace foundation
{

APIString::APIString(const char* s)
: m_s(duplicate_string(s))
{
}

APIString::APIString(const APIString& rhs)
: m_s(duplicate_string(rhs.m_s))
{
}

APIString::~APIString()
{
free_string(m_s);
}

const char* APIString::c_str() const
{
return m_s;
}

} // namespace foundation
Loading

0 comments on commit e842a3e

Please sign in to comment.