Skip to content

Commit

Permalink
C++ improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored May 26, 2024
1 parent 10a56cc commit da15bd1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
54 changes: 46 additions & 8 deletions BSystemTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4812,7 +4812,7 @@ public static String generateCopyOpsCPP()
" static string collectionToString(vector<_T>* c)\n" +
" { ostringstream buff;\n" +
" buff << \"Sequence{\";\n" +
" for (vector<_T>::iterator _pos = c->begin(); _pos != c->end(); ++_pos)\n" +
" for (auto _pos = c->begin(); _pos != c->end(); ++_pos)\n" +
" { buff << *_pos;\n" +
" if (_pos + 1 < c->end())\n" +
" { buff << \", \"; }\n" +
Expand All @@ -4822,15 +4822,24 @@ public static String generateCopyOpsCPP()
" }\n\n";

res = res +
" static string collectionToString(set<_T>* c)\n" +
" static string collectionToString(std::set<_T>* c)\n" +
" { ostringstream buff;\n" +
" buff << \"Set{\"; \n" +
" for (set<_T>::iterator _pos = c->begin(); _pos != c->end(); ++_pos)\n" +
" { buff << *_pos;\n" +
" if (_pos + 1 < c->end())\n" +
" { buff << \", \"; }\n" +
" auto _pos = c->begin(); \n" +
" if (_pos == c->end())\n" +
" {\n" +
" buff << \"}\";\n" +
" }\n" +
" else\n" +
" {\n" +
" buff << *_pos;\n" +
" ++_pos;\n" +
" for (; _pos != c->end(); ++_pos)\n" +
" { buff << \", \"; \n" +
" buff << *_pos;\n" +
" }\n" +
" buff << \"}\";\n" +
" }\n" +
" buff << \"}\";\n" +
" return buff.str(); \n" +
" }\n\n";

Expand Down Expand Up @@ -8137,6 +8146,20 @@ public static String generateSortOpCPP()
" std::sort(res->begin(), res->end());\n" +
" return res;\n" +
" }\n\n";

res = res + " static vector<_T>* sort(vector<_T>* a, std::function<bool(_T, _T)> f)\n" +
" { vector<_T>* res = new vector<_T>();\n" +
" res->insert(res->end(), a->begin(), a->end());\n" +
" std::sort(res->begin(), res->end(), f);\n" +
" return res;\n" +
" }\n\n" +
" static vector<_T>* sort(std::set<_T>* a, std::function<bool(_T, _T)> f)\n" +
" { vector<_T>* res = new vector<_T>();\n" +
" res->insert(res->end(), a->begin(), a->end());\n" +
" std::sort(res->begin(), res->end(), f);\n" +
" return res;\n" +
" }\n";

return res;
}

Expand Down Expand Up @@ -9716,8 +9739,10 @@ public static String generateRemoveSetAtOpsCPP()
" }\n\n";

res = res +
" static vector<_T>* removeSubrange(vector<_T>* l, int ind1, int ind2)\n" +
" static vector<_T>* excludingSubrange(vector<_T>* l, int ind1, int ind2)\n" +
" { vector<_T>* res = new vector<_T>();\n" +
" if (ind1 < 1) { ind1 = 1; }\n" +
" if (ind2 > l->size()) { ind2 = l->size(); }\n" +
" if (ind1 > 1 && ind1 <= l->size())\n" +
" {\n" +
" res->insert(res->end(), l->begin(), l->begin() + (ind1 - 2));\n" +
Expand All @@ -9729,6 +9754,19 @@ public static String generateRemoveSetAtOpsCPP()
" return l;\n" +
" }\n\n";

res = res +
" static string excludingSubrange(string l, int ind1, int ind2)\n" +
" { string res = \"\";\n" +
" if (ind1 < 1) { ind1 = 1; }\n" +
" if (ind2 > l.size()) { ind2 = l.size(); }\n" +
" if (ind1 > 1 && ind1 <= l.size())\n" +
" { res = l.substr(0,ind1-1); }\n" +
" if (ind2 >= ind1 && ind2 < l.size())\n" +
" { res = res + l.substr(ind2); }\n" +
" return res;\n" +
" }\n\n";


res = res + " static string removeAt(string ss, int ind)\n" +
" { if (ind >= 1 && ind <= ss.length())\n" +
" { string res = ss.substr(0,ind-1);\n" +
Expand Down
9 changes: 9 additions & 0 deletions BasicExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -9366,6 +9366,7 @@ else if (objectRef.isMultiple())
{ pre = "((" + ename + ") " + pre + ")"; }
res = pre + ".get" + data + "()";
}

if (arrayIndex != null)
{ String ind = arrayIndex.queryFormCSharp(env,local);
if (isQualified())
Expand Down Expand Up @@ -9690,6 +9691,14 @@ else if (data.equals("subrange") && parameters != null && parameters.size() == 1
String par2 = ue.queryFormCPP(env,local);
return "UmlRsdsLib<" + cetype + ">::subrange(" + pre + "," + par1 + "," + par2 + ")";
}
else if (data.equals("excludingSubrange") &&
parameters != null && parameters.size() > 1)
{ String par1 =
((Expression) parameters.get(0)).queryFormCPP(env,local);
String par2 =
((Expression) parameters.get(1)).queryFormCPP(env,local);
return "UmlRsdsLib<" + cetype + ">::excludingSubrange(" + pre + "," + par1 + "," + par2 + ")";
}
else if (data.equals("indexOf") && parameters != null && parameters.size() > 0) // for strings or sequences
{ String par1 = ((Expression) parameters.get(0)).queryFormCPP(env,local);
Type oreftype = objectRef.getType();
Expand Down
Binary file added cppUnitTestsSets.zip
Binary file not shown.
Binary file added cppUnitTestsVectors.zip
Binary file not shown.
14 changes: 10 additions & 4 deletions energyUseCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
# MemoryUse = 6 GB

# Energy use in W is then
# t*(cpu*43.2 + 2.235)
# t*(cpu*43.2 + mem*0.3725)

cpu = 0.9
durationMS = 4
cpustring = input("Input CPU utilisation 0 to 1: ")
cpu = float(cpustring)

energyUse = (durationMS/3600.0)*(cpu*43.2 + 2.235)
durstring = input("Input duration in milliseconds: ")
durationMS = int(durstring)

memstring = input("Input memory use in GB: ")
memuse = float(memstring)

energyUse = (durationMS/3600.0)*(cpu*43.2 + memuse*0.3725)

print(energyUse)

0 comments on commit da15bd1

Please sign in to comment.