This is not 1:1 conversion because some Term inner classes derive from
Term itself which is not allowed in C++. I therefore moved some of the
inner class definitions outside of Term.
Another painpoint is Terminal.bind() method which returns 'this'. I
changed the API to require callers to pass shared_ptr<terminal> which is
returned in place of 'this'. I went for shared_ptr because I wasn't able
to convince myself that the lifetime rules allow unique_ptr...
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
There are cf_statement derived classes that pass 'null' as 'cf_name'.
Switch to unique_ptr to allow that.
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
The conversion is not 1:1 because 'enum class' in C++ does not support
methods. As the methods are rather simple, I moved them out of the class
as standalone functions.
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
In the original Java code, MurmurHash was in the "utils" package, not
"util", so move it to a new "utils" directory (and namespace), not
"util".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
std::to_string() can also convert a floating-point argument to string,
using the "%f" printf format (see
http://en.cppreference.com/w/cpp/string/basic_string/to_string )
So add this support to our to_sstring() as well.
Note that if you want to use a different format, e.g., "%g", you can,
by using the to_sstring_sprintf function, for example
to_sstring_sprintf(12345678.9, "%g")
results in "1.23457e+07".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
We cannot keep a C++ reference to the statement object because we then
lose ownership information. Start using unique_ptr as suggested by Avi
instead.
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Unfortunately at_exit() cannot be used to delete objects since when
it runs the reactor is still active and deleted object may still been used.
We need another API that runs its task after reactor is already stopped.
at_destroy() will be such api.
Port the Murmur hash functions from Java to C++. This is ironic,
because these functions actually originated in C code, which the
Cassandra guys converted to Java :-)
The Murmur hash is used in Cassandra for several things, including the
bloom filter (which is part of each sstable), and the default
data partitioner (Murmur3Partitioner).
I tested on some example string that all three methods (hash32, hash2_64
and hash3_x64_128) produce exactly the same output in the new C++ code as
they do in the original Java functions. This is important, because we want
the C++ node to be able to run alongside Java nodes, so they have to agree
on the same hash function.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
[avi: update configure.py]
The constructor from "const char_type *" wouldn't really work when
char_type != char, because strlen() won't work on such pointers.
It is more convenient to have a constructor from an ordinary const char *
(e.g., a C string literal), and solve the type problem with an ugly cast.
This only makes sense when sizeof(char_type)==1 (i.e., it is char, unsigned
char, or signed char), but I think we make this assumption in other places
as well (e.g., in determining the size we need to allocate).
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
std::string has an operator[] to get access (read or modify) to one
character in the string. This patch adds the same operator for our
sstring.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>