zen0wu / topcoder-greed

greedy editor for topcoder arena
Apache License 2.0
229 stars 45 forks source link

Selecting the name for long long type in c++ #34

Closed vexorian closed 11 years ago

vexorian commented 11 years ago

A nitpick of mine is to use long and not long long (not very clean). The TC server now accepts long, so it is perfectly possible. But Greed sends the type as long long and there is no way in configuration to change this.

So i was trying to do it with template conditionals. Although the jmte page says that you can use = operator to compare string literals, it is not really working for me:

    ${if Method.ReturnType = "long long" }
        long
    ${end}

This would be perfect if it worked, but it seems that the condition returns true regardless of the string literal. I am not able to find good examples for how to do comparisons in jmte.

An elegant way to fix this in the plugin (if it is really impossible to do it with templates) would be to add a .LongInteger to the type predefined variables like .RealNumber and .String

Edit: After much attempts to do it with templates, I ended up concluding that changing code is an easier solution. This pull request adds a variable that can be used in Templates to determine if an argument is 64 bits integer. Also adds a configuration point to replace "long long" with another thing. Some guys prefer to use LL, or int64 (with a typedef), so maybe it is useful for all.

vexorian commented 11 years ago

With that patch, my template now looks like this:

#include <bits/stdc++.h>
using namespace std;
struct ${ClassName}
{
    ${if Method.ReturnType.LongInteger}${if Method.ReturnType.Array}vector${else}long${end}${else}${Method.ReturnType}${end}${--
    } ${Method.Name}(${foreach Method.Params p , }${if p.Type.LongInteger}${if p.Type.Array}vector${else}long${end}${else}${p.Type}${end} ${p.Name}${end})
    {
        return ${Method.ReturnType;ZeroValue};
    }
};
${CutBegin}
${<TestCode}
${CutEnd}

It is a bit messsy, but it works, and now vector and long long are changed to long.

A configuration entry to replace the "long long" text with something else would have made a cleaner template (and other people might find it useful, I heard some like to change it with int64), but perhaps would be overkill for such a singular issue.

vexorian commented 11 years ago

Hi, I closed the other pull request , because it was using my master branch and also because two issues for the same topic was too much annoyance.

zen0wu commented 11 years ago

OK, I see your point here, that makes sense. I did not know that C++ in topcoder can accept long as long long. This is only for C++, right? I think cpp.spec.longIntTypeName is a better configuration key, more clear in semantic.

vexorian commented 11 years ago

Ok changed it. Note that this branch also adds .isLongInteger to the parameter object in templates.

zen0wu commented 11 years ago

Yes, I know that. Did you change the value in the default configuration?

vexorian commented 11 years ago

Sorry, I fixed that.

zen0wu commented 11 years ago

Good, Thanks. FYI, in fact you can just write spec.longIntTypeName, but that's OK.

wookayin commented 11 years ago

Nice work. Please don't forget wiki also :)