Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new cli-tool #24

Merged
merged 113 commits into from
Apr 19, 2018
Merged

Introduce new cli-tool #24

merged 113 commits into from
Apr 19, 2018

Conversation

j-beyer
Copy link
Contributor

@j-beyer j-beyer commented Feb 12, 2018

This PR introduces the new command line interface for glkernel.

As discussed in our e-mail, there are still open issues which can be found under https://github.com/p-otto/glkernel/issues

#25 should be merged before this, to make the code generation work correctly.
Additionally, #26 should be merged together with this, as it removes the old command line interface.

j-beyer and others added 30 commits November 20, 2017 15:55
Rewrite CLI using cppassist::CommandLineProgram
…i-tool

# Conflicts:
#	source/tools/glkernel-cli/main.cpp
  Working:
    - Creating kernels from JS (currently only kernel<float>)
    - Calling e.g. kernel.sequence.uniform()
  Missing:
    - Expose more functions
  - Added scale::range and sort::distance
  - Figured out JS default parameters (see sort.distance)
  - Started JS-sided detection of parameter type
@j-beyer j-beyer mentioned this pull request Feb 22, 2018
@@ -14,6 +14,8 @@

namespace
{
using uint = unsigned int;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this type isn't used anymore. Additionally, I advise against using this type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a compile fix for the to-be-deprecated glkernel-cmd.

}

std::string extractOutputFormat(const std::string & outFileName, const bool shouldConvert) {
if (outFileName.find('.') == std::string::npos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a doubled search for '.' in the string. Search it once (outFileName.find_last_of('.')), store the result and reuse it both times.



std::string extractInputFormat(const std::string & inFileName) {
if (inFileName.find('.') == std::string::npos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a doubled search for '.' in the string. Search it once (inFileName.find_last_of('.')), store the result and reuse it both times.

Generally, you're performing file name operations, that are implemented in cppassist as well: https://github.com/cginternals/cppassist/blob/master/source/cppassist/include/cppassist/fs/FilePath.h

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

bool canBeVec2(const cppexpose::Variant & v) {
const auto arr = v.asArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversion may fail, at least assert against nullptr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this returns a nullptr we return false, since this conversion did not work.

float min = std::numeric_limits<float>::max();
float max = std::numeric_limits<float>::min();
const auto end = kernel.cend();
for (auto it = kernel.cbegin(); it != end; ++it)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding a const-overloaded begin and end to tkernel and use a range-based for loop instead:

for (const auto & p : kernel)
{
    const auto x = p.x;
    const auto y = p.y;

    //...
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
public:
Kernel4Object(int width, int height, int depth);
glkernel::kernel4& kernel();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please switch to 4 spaces instead of tabs.


#include <cppassist/logging/logging.h>

void forEachCell(cppexpose::VariantArray * depthArray, std::function<void(const cppexpose::Variant&)> lambda)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you provide an forEachCell overload where the lambda takes the current index as second parameter.



std::string JsonExporter::stringify(const cppexpose::Variant &array) {
auto outputMode = m_beautify
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outputMode may be const, too.

auto outputMode = m_beautify
? cppexpose::JSON::OutputMode::Beautify
: cppexpose::JSON::OutputMode::Compact;
return cppexpose::JSON::stringify(array, outputMode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once cginternals/cppexpose#56 is implemented, you should use the interface writing to a stream.

JsonImporter.h
PngExporter.h
helper.h
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We choose to indent the closing brace as much as the line containing the opening one. In this case: no identation.

@j-beyer j-beyer changed the title WIP: glkernel cli-tool glkernel cli-tool Mar 30, 2018
@j-beyer j-beyer changed the title glkernel cli-tool Introduce new cli-tool Mar 30, 2018
@cgcostume cgcostume merged commit 524f951 into cginternals:master Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants