Skip to content

Commit 0daf645

Browse files
author
Keith A. Lewis
committed
Added headers
Added casts
1 parent db1c0c9 commit 0daf645

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

Diff for: sort.cpp

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
11
// sort.cpp - std::sort from the STL
2-
//!!! Write xll_sort that calls std::sort and hook it up to XLL.SORT in Excel.
2+
#include <algorithm>
3+
#include <xutility>
4+
#include "G5260.h"
5+
6+
using namespace xll;
7+
8+
AddIn xai_sort(
9+
Function(XLL_LPOPER, L"?xll_sort", L"XLL.SORT")
10+
.Arg(XLL_LPOPER, L"range", L"is a range.")
11+
.FunctionHelp(L"Sort entries from range.")
12+
.Category(CATEGORY)
13+
);
14+
LPOPER WINAPI xll_sort(LPOPER po)
15+
{
16+
#pragma XLLEXPORT
17+
static OPER o;
18+
19+
try {
20+
std::sort(po->begin(), po->end());
21+
if (po->rows() == 1) {
22+
o.resize(1, po->columns());
23+
}
24+
else {
25+
o.resize(po->rows(), po->columns());
26+
}
27+
std::copy(po->begin(), po->end(), o.begin());
28+
}
29+
catch (const std::exception& ex) {
30+
XLL_ERROR(ex.what());
31+
o = OPER(xlerr::NA);
32+
}
33+
34+
return &o;
35+
}
36+

Diff for: unique.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// unique.cpp - std::unique from the STL
2+
#include <algorithm>
3+
#include <xutility>
24
#include "G5260.h"
35

46
using namespace xll;
@@ -17,10 +19,10 @@ LPOPER WINAPI xll_unique(LPOPER po)
1719
try {
1820
auto e = std::unique(po->begin(), po->end());
1921
if (po->rows() == 1) {
20-
o.resize(1, std::distance(po->begin(), e));
22+
o.resize(1, (COL)std::distance(po->begin(), e));
2123
}
2224
else {
23-
o.resize(std::distance(po->begin(), e), 1);
25+
o.resize((RW)std::distance(po->begin(), e), 1);
2426
}
2527
std::copy(po->begin(), e, o.begin());
2628
}

0 commit comments

Comments
 (0)