https://codereview.appspot.com/239300043/diff/1/source/test/intltest/Makefile.in File source/test/intltest/Makefile.in (right): https://codereview.appspot.com/239300043/diff/1/source/test/intltest/Makefile.in#newcode61 source/test/intltest/Makefile.in:61: scientificnumberformattertest.o datadrivennumberformattestsuite.o \ We are going to need the ...
8 years, 11 months ago
(2015-05-26 23:30:27 UTC)
#2
8 years, 10 months ago
(2015-05-27 21:33:24 UTC)
#4
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/numberfo...
File source/test/intltest/numberformattesttuple.cpp (right):
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/numberfo...
source/test/intltest/numberformattesttuple.cpp:19: #define
FIELD_OFFSET(fieldName) ((int32_t) (((char *) &gNullPtr->fieldName) - ((char *)
gNullPtr)))
On 2015/05/26 23:30:26, andy.heninger wrote:
> This kind of pointer arithmetic and casting makes me nervous, it seems like
the
> various static checker tools keep ratcheting up the things they complain
about.
Maybe there is some way to use a C++ pointer to data member, which is pretty
much the same thing inside, an offset within an object.
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/numberfo...
source/test/intltest/numberformattesttuple.cpp:287: const
NumberFormatTestTupleFieldOps *ops;
So we are assembling structs with virtual functions implemented as pointers to C
functions.
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/numberfo...
source/test/intltest/numberformattesttuple.cpp:441:
Here's an approach to doing the tuple field access without all the casting and
unsafe pointer arithmetic, but otherwise keeping the structure similar to what
it is.
class Tuple {
public:
int32_t a;
int32_t b;
int32_t c;
UnicodeString s;
double d;
void setByName(const char *field, UnicodeString value);
UnicodeString &appendByName(const char *field, UnicodeString &appendTo);
};
struct TupleItem {
TupleItem(const char *name) {fName = name;};
const char *fName;
virtual void set(Tuple *tuple, const UnicodeString &value) = 0;
virtual UnicodeString &toString(Tuple *tuple, UnicodeString &appendTo) = 0;
};
struct IntItem: public TupleItem {
IntItem(const char *name, int Tuple::*pdata) : TupleItem(name),
fpdata(pdata) {};
int32_t Tuple::*fpdata;
void set(Tuple *tuple, const UnicodeString &value) {
// value = convert the string.
tuple->*fpdata = 0 /* value */;
}
UnicodeString &toString(Tuple *tuple, UnicodeString &appendTo) {
int32_t v = tuple->*fpdata;
// Append v to the string.
return appendTo;
}
};
struct StringItem: public TupleItem {
StringItem(const char *name, UnicodeString Tuple::*pdata) : TupleItem(name),
fpdata(pdata) {};
UnicodeString Tuple::*fpdata;
void set(Tuple *tuple, const UnicodeString &value) {
tuple->*fpdata = value;
}
UnicodeString &toString(Tuple *tuple, UnicodeString &appendTo) {
appendTo.append(tuple->*fpdata);
return appendTo;
}
};
int main() {
TupleItem *tupleDesc[] = {
new IntItem("a", &Tuple::a),
new IntItem("b", &Tuple::b),
new IntItem("c", &Tuple::c),
new StringItem("s", &Tuple::s)
};
Not clear if its worth changing, though, since its working as it is.
The thing is really a map of field names to fields. Too bad we can't use std
classes. UHash might save a few lines of code in handling name lookups, and keep
the intent clear.
8 years, 10 months ago
(2015-05-27 21:57:12 UTC)
#5
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/Makefile.in
File source/test/intltest/Makefile.in (right):
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/Makefile...
source/test/intltest/Makefile.in:61: scientificnumberformattertest.o
datadrivennumberformattestsuite.o \
On 2015/05/27 18:02:43, tkeep wrote:
> On 2015/05/26 23:30:26, andy.heninger wrote:
> > We are going to need the corresponding additions to the visual studio
project
> > files.
>
> Will do this part in a separate commit.
Done.
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/numberfo...
File source/test/intltest/numberformattesttuple.cpp (right):
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/numberfo...
source/test/intltest/numberformattesttuple.cpp:287: const
NumberFormatTestTupleFieldOps *ops;
On 2015/05/27 21:33:24, andy.heninger wrote:
> So we are assembling structs with virtual functions implemented as pointers to
C
> functions.
Not sure what you are asking me to do here.
https://codereview.appspot.com/239300043/diff/1/source/test/intltest/numberfo...
source/test/intltest/numberformattesttuple.cpp:441:
On 2015/05/27 21:33:24, andy.heninger wrote:
> Here's an approach to doing the tuple field access without all the casting and
> unsafe pointer arithmetic, but otherwise keeping the structure similar to what
> it is.
>
> class Tuple {
> public:
> int32_t a;
> int32_t b;
> int32_t c;
>
> UnicodeString s;
> double d;
>
> void setByName(const char *field, UnicodeString value);
> UnicodeString &appendByName(const char *field, UnicodeString &appendTo);
> };
>
> struct TupleItem {
> TupleItem(const char *name) {fName = name;};
>
> const char *fName;
> virtual void set(Tuple *tuple, const UnicodeString &value) = 0;
> virtual UnicodeString &toString(Tuple *tuple, UnicodeString &appendTo) =
0;
> };
>
> struct IntItem: public TupleItem {
> IntItem(const char *name, int Tuple::*pdata) : TupleItem(name),
> fpdata(pdata) {};
> int32_t Tuple::*fpdata;
>
> void set(Tuple *tuple, const UnicodeString &value) {
> // value = convert the string.
> tuple->*fpdata = 0 /* value */;
> }
>
> UnicodeString &toString(Tuple *tuple, UnicodeString &appendTo) {
> int32_t v = tuple->*fpdata;
> // Append v to the string.
> return appendTo;
> }
> };
>
> struct StringItem: public TupleItem {
> StringItem(const char *name, UnicodeString Tuple::*pdata) :
TupleItem(name),
> fpdata(pdata) {};
> UnicodeString Tuple::*fpdata;
>
> void set(Tuple *tuple, const UnicodeString &value) {
> tuple->*fpdata = value;
> }
>
> UnicodeString &toString(Tuple *tuple, UnicodeString &appendTo) {
> appendTo.append(tuple->*fpdata);
> return appendTo;
> }
> };
>
>
> int main() {
> TupleItem *tupleDesc[] = {
> new IntItem("a", &Tuple::a),
> new IntItem("b", &Tuple::b),
> new IntItem("c", &Tuple::c),
> new StringItem("s", &Tuple::s)
> };
>
> Not clear if its worth changing, though, since its working as it is.
>
> The thing is really a map of field names to fields. Too bad we can't use std
> classes. UHash might save a few lines of code in handling name lookups, and
keep
> the intent clear.
Are you ok with trying what I have out in the trunk? If it breaks, we will know
within 1 to 2 hours. Then we can decide whether doing this change is worth it?
Does that sound reasonable? Of course I have never rolled back a commit to trunk
before.
Issue 239300043: Data Driven Tests for DecimalFormat.
Created 8 years, 11 months ago by tkeep
Modified 8 years, 10 months ago
Reviewers: andy.heninger
Base URL: svn+ssh://source.icu-project.org/repos/icu/icu/branches/tkeep/11692/
Comments: 27