IGNITE-2879: ODBC: Added decimal support.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5cc1f074 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5cc1f074 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5cc1f074 Branch: refs/heads/ignite-1232 Commit: 5cc1f074d038b1883ff8a5fd08729e1ce8dcf9f8 Parents: 7d4b159 Author: vozerov-gridgain <[email protected]> Authored: Mon Jun 27 15:23:31 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Mon Jun 27 15:23:31 2016 +0300 ---------------------------------------------------------------------- .../include/ignite/binary/binary_containers.h | 6 +- .../include/ignite/binary/binary_raw_reader.h | 6 +- .../include/ignite/binary/binary_reader.h | 6 +- .../ignite/impl/binary/binary_reader_impl.h | 11 +- .../ignite/impl/binary/binary_writer_impl.h | 2 +- modules/platforms/cpp/common/Makefile.am | 5 +- .../platforms/cpp/common/include/Makefile.am | 19 +- .../common/include/ignite/common/big_integer.h | 523 +++++++++ .../cpp/common/include/ignite/common/bits.h | 218 ++++ .../include/ignite/common/default_allocator.h | 95 ++ .../include/ignite/common/dynamic_size_array.h | 415 +++++++ .../include/ignite/common/fixed_size_array.h | 288 +++++ .../cpp/common/include/ignite/common/utils.h | 81 +- .../platforms/cpp/common/include/ignite/guid.h | 4 +- .../cpp/common/os/win/src/common/utils.cpp | 21 - .../cpp/common/project/vs/common.vcxproj | 17 +- .../common/project/vs/common.vcxproj.filters | 27 + .../cpp/common/src/common/big_integer.cpp | 830 +++++++++++++ .../platforms/cpp/common/src/common/bits.cpp | 233 ++++ modules/platforms/cpp/core-test/Makefile.am | 4 + .../cpp/core-test/project/vs/core-test.vcxproj | 7 + .../project/vs/core-test.vcxproj.filters | 12 + .../platforms/cpp/core-test/src/bits_test.cpp | 124 ++ .../cpp/core-test/src/decimal_test.cpp | 1101 ++++++++++++++++++ .../core-test/src/dynamic_size_array_test.cpp | 360 ++++++ .../cpp/core-test/src/fixed_size_array_test.cpp | 208 ++++ .../cpp/core/include/ignite/cache/cache_entry.h | 2 +- modules/platforms/cpp/odbc-test/Makefile.am | 1 - .../cpp/odbc-test/project/vs/odbc-test.vcxproj | 1 - .../project/vs/odbc-test.vcxproj.filters | 3 - .../src/application_data_buffer_test.cpp | 35 +- .../platforms/cpp/odbc-test/src/row_test.cpp | 5 +- modules/platforms/cpp/odbc/Makefile.am | 1 - modules/platforms/cpp/odbc/include/Makefile.am | 1 - .../ignite/odbc/app/application_data_buffer.h | 11 +- .../cpp/odbc/include/ignite/odbc/decimal.h | 137 --- .../cpp/odbc/include/ignite/odbc/utility.h | 12 +- .../platforms/cpp/odbc/project/vs/odbc.vcxproj | 2 - .../cpp/odbc/project/vs/odbc.vcxproj.filters | 6 - .../odbc/src/app/application_data_buffer.cpp | 210 +++- .../platforms/cpp/odbc/src/app/parameter.cpp | 6 +- modules/platforms/cpp/odbc/src/column.cpp | 6 +- modules/platforms/cpp/odbc/src/connection.cpp | 1 - modules/platforms/cpp/odbc/src/decimal.cpp | 135 --- modules/platforms/cpp/odbc/src/odbc.cpp | 3 - modules/platforms/cpp/odbc/src/utility.cpp | 25 +- 46 files changed, 4759 insertions(+), 467 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/binary/include/ignite/binary/binary_containers.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_containers.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_containers.h index 8f26416..9938dd5 100644 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_containers.h +++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_containers.h @@ -342,11 +342,11 @@ namespace ignite if (len != -1) { - common::SafeArray<char> arr(len + 1); + ignite::common::FixedSizeArray<char> arr(len + 1); - GetNext(arr.target, len + 1); + GetNext(arr.GetData(), static_cast<int32_t>(arr.GetSize())); - return std::string(arr.target); + return std::string(arr.GetData()); } else return std::string(); http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/binary/include/ignite/binary/binary_raw_reader.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_raw_reader.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_raw_reader.h index 3104437..72aab55 100644 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_raw_reader.h +++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_raw_reader.h @@ -298,11 +298,11 @@ namespace ignite if (len != -1) { - ignite::common::SafeArray<char> arr(len + 1); + ignite::common::FixedSizeArray<char> arr(len + 1); - ReadString(arr.target, len + 1); + ReadString(arr.GetData(), static_cast<int32_t>(arr.GetSize())); - return std::string(arr.target); + return std::string(arr.GetData()); } else return std::string(); http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/binary/include/ignite/binary/binary_reader.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_reader.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_reader.h index ac70f39..e4eb690 100644 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_reader.h +++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_reader.h @@ -321,11 +321,11 @@ namespace ignite if (len != -1) { - ignite::common::SafeArray<char> arr(len + 1); + ignite::common::FixedSizeArray<char> arr(len + 1); - ReadString(fieldName, arr.target, len + 1); + ReadString(fieldName, arr.GetData(), static_cast<int32_t>(arr.GetSize())); - return std::string(arr.target); + return std::string(arr.GetData()); } else return std::string(); http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h index d2a4e24..71b4e61 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h @@ -21,6 +21,7 @@ #include <stdint.h> #include <ignite/common/common.h> +#include <ignite/common/fixed_size_array.h> #include "ignite/impl/interop/interop_input_stream.h" #include "ignite/impl/binary/binary_common.h" @@ -1397,14 +1398,14 @@ namespace ignite { int32_t realLen = stream->ReadInt32(); - ignite::common::SafeArray<char> arr(realLen + 1); + ignite::common::FixedSizeArray<char> arr(realLen + 1); - for (int i = 0; i < realLen; i++) - *(arr.target + i) = static_cast<char>(stream->ReadInt8()); + for (int32_t i = 0; i < realLen; i++) + arr[i] = static_cast<char>(stream->ReadInt8()); - *(arr.target + realLen) = 0; + arr[realLen] = 0; - return std::string(arr.target); + return std::string(arr.GetData()); } else if (typeId == IGNITE_HDR_NULL) http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h index fda507f..6ee088d 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h @@ -972,7 +972,7 @@ namespace ignite { const char* obj0 = obj.c_str(); - int32_t len = static_cast<int32_t>(strlen(obj0)); + int32_t len = static_cast<int32_t>(obj.size()); stream->WriteInt8(IGNITE_TYPE_STRING); http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/Makefile.am b/modules/platforms/cpp/common/Makefile.am index 6956627..c230384 100644 --- a/modules/platforms/cpp/common/Makefile.am +++ b/modules/platforms/cpp/common/Makefile.am @@ -42,9 +42,12 @@ libignite_common_la_LDFLAGS = \ libignite_common_la_SOURCES = \ os/linux/src/common/concurrent_os.cpp \ os/linux/src/common/utils.cpp \ + src/common/big_integer.cpp \ src/common/concurrent.cpp \ - src/ignite_error.cpp \ + src/common/decimal.cpp \ + src/common/bits.cpp \ src/date.cpp \ + src/ignite_error.cpp \ src/guid.cpp \ src/timestamp.cpp http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/Makefile.am b/modules/platforms/cpp/common/include/Makefile.am index b18d6f8..2e53608 100644 --- a/modules/platforms/cpp/common/include/Makefile.am +++ b/modules/platforms/cpp/common/include/Makefile.am @@ -18,12 +18,19 @@ ACLOCAL_AMFLAGS =-I m4 nobase_include_HEADERS = \ - ignite/common/concurrent.h \ - ignite/common/utils.h \ - ignite/ignite_error.h \ - ignite/date.h \ - ignite/guid.h \ - ignite/timestamp.h + ignite/common/big_integer.h \ + ignite/common/bits.h \ + ignite/common/concurrent.h \ + ignite/common/decimal.h \ + ignite/common/default_allocator.h \ + ignite/common/dynamic_size_array.h \ + ignite/common/fixed_size_array.h \ + ignite/common/utils.h \ + ignite/date.h \ + ignite/guid.h \ + ignite/ignite_error.h \ + ignite/timestamp.h + ignite/timestamp.h uninstall-hook: if [ -d ${includedir}/ignite ]; then find ${includedir}/ignite -type d -empty -delete; fi http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/ignite/common/big_integer.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/big_integer.h b/modules/platforms/cpp/common/include/ignite/common/big_integer.h new file mode 100644 index 0000000..ceddd8f --- /dev/null +++ b/modules/platforms/cpp/common/include/ignite/common/big_integer.h @@ -0,0 +1,523 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_COMMON_BIG_INTEGER +#define _IGNITE_COMMON_BIG_INTEGER + +#include <stdint.h> + +#include <iostream> +#include <vector> + +#include <ignite/common/dynamic_size_array.h> + +namespace ignite +{ + namespace common + { + /** + * Big integer number implementation. + */ + class BigInteger + { + friend class Decimal; + public: + // Magnitude array type. + typedef DynamicSizeArray<uint32_t> MagArray; + + /** + * Default constructor. Constructs zero-value big integer. + */ + BigInteger(); + + /** + * Constructs big integer with the specified integer value. + * + * @param val Value. + */ + explicit BigInteger(int64_t val); + + /** + * String constructor. + * + * @param val String to assign. + * @param len String length. + */ + BigInteger(const char* val, int32_t len); + + /** + * String constructor. + * + * @param val String to assign. + */ + explicit BigInteger(const std::string& val) : + sign(1), + mag() + { + AssignString(val); + } + + /** + * Copy constructor. + * + * @param other Other value. + */ + BigInteger(const BigInteger& other); + + /** + * Constructs big integer from the byte array. + * + * @param val Bytes of the integer. Byte order is big-endian. + * @param len Array length. + * @param sign Signum. Can be -1 (negative) or 1 (positive or zero). + * @param bigEndian If true then magnitude is in big-endian. Otherwise + * the byte order of the magnitude considered to be little-endian. + */ + BigInteger(const int8_t* val, int32_t len, int32_t sign, bool bigEndian = true); + + /** + * Constructs big integer with the specified magnitude. + * @warning Magnitude is moved. This mean mag left empty after the call. + * + * @param mag Magnitude. Moved. + * @param sign Sign. Can be 1 or -1. + */ + BigInteger(MagArray& mag, int8_t sign); + + /** + * Assigment operator. + * + * @param other Other value. + * @return *this. + */ + BigInteger& operator=(const BigInteger& other); + + /** + * Assign specified value to this BigInteger. + * + * @param val Value to assign. + */ + void Assign(const BigInteger& val); + + /** + * Assign specified value to this BigInteger. + * + * @param val Value to assign. + */ + void AssignInt64(int64_t val); + + /** + * Assign specified value to this Decimal. + * + * @param val String to assign. + */ + void AssignString(const std::string& val) + { + AssignString(val.data(), static_cast<int32_t>(val.size())); + } + + /** + * Assign specified value to this Decimal. + * + * @param val String to assign. + * @param len String length. + */ + void AssignString(const char* val, int32_t len); + + /** + * Assign specified value to this BigInteger. + * + * @param val Value to assign. + */ + void AssignUint64(uint64_t val); + + /** + * Get number sign. Returns -1 if negative and 1 otherwise. + * + * @return Sign of the number. + */ + int8_t GetSign() const; + + /** + * Swap function for the BigInteger type. + * + * @param other Other instance. + */ + void Swap(BigInteger& other); + + /** + * Get magnitude array. + * + * @return magnitude array. + */ + const MagArray& GetMagnitude() const; + + /** + * Get this number length in bits as if it was positive. + * + * @return Number length in bits. + */ + uint32_t GetBitLength() const; + + /** + * Get precision of the BigInteger. + * + * @return Number of the decimal digits in the decimal representation + * of the value. + */ + int32_t GetPrecision() const; + + /** + * Fills specified buffer with data of this BigInteger converted to + * bytes in big-endian byte order. Sign is not considered when this + * operation is performed. + * + * @param buffer Buffer to fill. + */ + void MagnitudeToBytes(common::FixedSizeArray<int8_t>& buffer) const; + + /** + * Mutates this BigInteger so its value becomes exp power of this. + * + * @param exp Exponent. + */ + void Pow(int32_t exp); + + /** + * Muitiply this to another big integer. + * + * @param other Another instance. Can be *this. + * @param res Result placed there. Can be *this. + */ + void Multiply(const BigInteger& other, BigInteger& res) const; + + /** + * Divide this to another big integer. + * + * @param divisor Divisor. Can be *this. + * @param res Result placed there. Can be *this. + */ + void Divide(const BigInteger& divisor, BigInteger& res) const; + + /** + * Divide this to another big integer. + * + * @param divisor Divisor. Can be *this. + * @param res Result placed there. Can be *this. + * @param rem Remainder placed there. Can be *this. + */ + void Divide(const BigInteger& divisor, BigInteger& res, BigInteger& rem) const; + + /** + * Add unsigned integer number to this BigInteger. + * + * @param x Number to add. + */ + void Add(uint64_t x); + + /** + * Compare this instance to another. + * + * @param other Another instance. + * @param ignoreSign If set to true than only magnitudes are compared. + * @return Comparasion result - 0 if equal, 1 if this is greater, -1 if + * this is less. + */ + int32_t Compare(const BigInteger& other, bool ignoreSign = false) const; + + /** + * Convert to int64_t. + * + * @return int64_t value. + */ + int64_t ToInt64() const; + + /** + * Check whether this value is negative. + * + * @return True if this value is negative and false otherwise. + */ + bool IsNegative() const + { + return sign < 0; + } + + /** + * Check whether this value is zero. + * + * @return True if this value is negative and false otherwise. + */ + bool IsZero() const + { + return mag.GetSize() == 0; + } + + /** + * Check whether this value is positive. + * + * @return True if this value is positive and false otherwise. + */ + bool IsPositive() const + { + return sign > 0 && !IsZero(); + } + + /** + * Rverses sign of this value. + */ + void Negate() + { + if (!IsZero()) + sign = -sign; + } + + /** + * Output operator. + * + * @param os Output stream. + * @param val Value to output. + * @return Reference to the first param. + */ + friend std::ostream& operator<<(std::ostream& os, const BigInteger& val) + { + if (val.IsZero()) + return os << '0'; + + if (val.sign < 0) + os << '-'; + + const int32_t maxResultDigits = 19; + BigInteger maxUintTenPower; + BigInteger res; + BigInteger left; + + maxUintTenPower.AssignUint64(10000000000000000000ULL); + + std::vector<uint64_t> vals; + + val.Divide(maxUintTenPower, left, res); + + if (res.sign < 0) + res.sign = -res.sign; + + if (left.sign < 0) + left.sign = -left.sign; + + vals.push_back(static_cast<uint64_t>(res.ToInt64())); + + while (!left.IsZero()) + { + left.Divide(maxUintTenPower, left, res); + + vals.push_back(static_cast<uint64_t>(res.ToInt64())); + } + + os << vals.back(); + + for (int32_t i = static_cast<int32_t>(vals.size()) - 2; i >= 0; --i) + { + os.fill('0'); + os.width(maxResultDigits); + + os << vals[i]; + } + + return os; + } + + /** + * Input operator. + * + * @param is Input stream. + * @param val Value to input. + * @return Reference to the first param. + */ + friend std::istream& operator>>(std::istream& is, BigInteger& val) + { + std::istream::sentry sentry(is); + + // Return zero if input failed. + val.AssignInt64(0); + + if (!is) + return is; + + // Current value parts. + uint64_t part = 0; + int32_t partDigits = 0; + int32_t sign = 1; + + BigInteger pow; + BigInteger bigPart; + + // Current char. + int c = is.peek(); + + if (!is) + return is; + + // Checking sign. + if (c == '-' || c == '+') + { + if (c == '-') + sign = -1; + + is.ignore(); + c = is.peek(); + } + + // Reading number itself. + while (is && isdigit(c)) + { + part = part * 10 + (c - '0'); + ++partDigits; + + if (part >= 1000000000000000000ULL) + { + BigInteger::GetPowerOfTen(partDigits, pow); + val.Multiply(pow, val); + + val.Add(part); + + part = 0; + partDigits = 0; + } + + is.ignore(); + c = is.peek(); + } + + // Adding last part of the number. + if (partDigits) + { + BigInteger::GetPowerOfTen(partDigits, pow); + + val.Multiply(pow, val); + + val.Add(part); + } + + if (sign < 0) + val.Negate(); + + return is; + } + + /** + * Get BigInteger which value is the ten of the specified power. + * + * @param pow Tenth power. + * @param res Result is placed here. + */ + static void GetPowerOfTen(int32_t pow, BigInteger& res); + + private: + /** + * Add magnitude array to current. + * + * @param addend Addend. + * @param len Length of the addend. + */ + void Add(const uint32_t* addend, int32_t len); + + /** + * Get n-th integer of the magnitude. + * + * @param n Index. + * @return Value of the n-th int of the magnitude. + */ + uint32_t GetMagInt(int32_t n) const; + + /** + * Divide this to another big integer. + * + * @param divisor Divisor. Can be *this. + * @param res Result placed there. Can be *this. + * @param rem Remainder placed there if requested. Can be *this. + * Can be null if the remainder is not needed. + */ + void Divide(const BigInteger& divisor, BigInteger& res, BigInteger* rem) const; + + /** + * Normalizes current value removing trailing zeroes from the magnitude. + */ + void Normalize(); + + /** The sign of this BigInteger: -1 for negative and 1 for non-negative. */ + int8_t sign; + + /** The magnitude of this BigInteger. Byte order is little-endian. */ + MagArray mag; + }; + + /** + * Comparison operator. + * + * @param val1 First value. + * @param val2 Second value. + * @return True if equal. + */ + bool IGNITE_IMPORT_EXPORT operator==(const BigInteger& val1, const BigInteger& val2); + + /** + * Comparison operator. + * + * @param val1 First value. + * @param val2 Second value. + * @return True if not equal. + */ + bool IGNITE_IMPORT_EXPORT operator!=(const BigInteger& val1, const BigInteger& val2); + + /** + * Comparison operator. + * + * @param val1 First value. + * @param val2 Second value. + * @return True if less. + */ + bool IGNITE_IMPORT_EXPORT operator<(const BigInteger& val1, const BigInteger& val2); + + /** + * Comparison operator. + * + * @param val1 First value. + * @param val2 Second value. + * @return True if less or equal. + */ + bool IGNITE_IMPORT_EXPORT operator<=(const BigInteger& val1, const BigInteger& val2); + + /** + * Comparison operator. + * + * @param val1 First value. + * @param val2 Second value. + * @return True if gretter. + */ + bool IGNITE_IMPORT_EXPORT operator>(const BigInteger& val1, const BigInteger& val2); + + /** + * Comparison operator. + * + * @param val1 First value. + * @param val2 Second value. + * @return True if gretter or equal. + */ + bool IGNITE_IMPORT_EXPORT operator>=(const BigInteger& val1, const BigInteger& val2); + } +} + +#endif //_IGNITE_COMMON_BIG_INTEGER \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/ignite/common/bits.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/bits.h b/modules/platforms/cpp/common/include/ignite/common/bits.h new file mode 100644 index 0000000..5722215 --- /dev/null +++ b/modules/platforms/cpp/common/include/ignite/common/bits.h @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _IGNITE_COMMON_BITS +#define _IGNITE_COMMON_BITS + +#include <stdint.h> + +#include <ignite/common/common.h> +#include <ignite/common/fixed_size_array.h> + +namespace ignite +{ + namespace common + { + namespace bits + { + /** + * Maximum number of digits in uint64_t number. + */ + const int32_t UINT64_MAX_PRECISION = 20; + + /** + * Get number of trailing zero bits in the two's complement binary + * representation of the specified 32-bit int value. + * + * @param i The value whose bits are to be counted. + * @return The number of trailing zero bits in the two's complement + * binary representation of the specified 32-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t NumberOfTrailingZerosI32(int32_t i); + + /** + * Get number of leading zero bits in the two's complement binary + * representation of the specified 32-bit int value. + * + * @param i The value whose bits are to be counted. + * @return The number of leading zero bits in the two's complement + * binary representation of the specified 32-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t NumberOfLeadingZerosI32(int32_t i); + + /** + * Get number of leading zero bits in the two's complement binary + * representation of the specified 32-bit int value. + * + * @param i The value whose bits are to be counted. + * @return The number of leading zero bits in the two's complement + * binary representation of the specified 32-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t NumberOfLeadingZerosU32(uint32_t i); + + /** + * Get number of leading zero bits in the two's complement binary + * representation of the specified 64-bit int value. + * + * @param i The value whose bits are to be counted. + * @return The number of leading zero bits in the two's complement + * binary representation of the specified 64-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t NumberOfLeadingZerosI64(int64_t i); + + /** + * Get number of leading zero bits in the two's complement binary + * representation of the specified 64-bit int value. + * + * @param i The value whose bits are to be counted. + * @return The number of leading zero bits in the two's complement + * binary representation of the specified 64-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t NumberOfLeadingZerosU64(uint64_t i); + + /** + * Get the number of one-bits in the two's complement binary + * representation of the specified 32-bit int value. + * + * @param i The value whose bits are to be counted. + * @return The number of one-bits in the two's complement binary + * representation of the specified 32-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t BitCountI32(int32_t i); + + /** + * Get bit length for the specified signed 32-bit int value. + * + * @param i The value to get bit length for. + * @return The number of significant bits in the two's complement binary + * representation of the specified 32-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t BitLengthI32(int32_t i); + + /** + * Get bit length for the specified unsigned 32-bit int value. + * + * @param i The value to get bit length for. + * @return The number of significant bits in the two's complement binary + * representation of the specified 32-bit int value. + */ + IGNITE_IMPORT_EXPORT int32_t BitLengthU32(uint32_t i); + + /** + * Calcutale capasity for required size. + * Rounds up to the nearest power of two. + * + * @param size Needed capasity. + * @return Recomended capasity to allocate. + */ + IGNITE_IMPORT_EXPORT int32_t GetCapasityForSize(int32_t size); + + /** + * Get the number of decimal digits of the integer value. + * + * @param x The value. + * @return The number of decimal digits of the integer value. + */ + IGNITE_IMPORT_EXPORT int32_t DigitLength(uint64_t x); + + /** + * Get n-th power of ten. + * + * @param n Power. Should be in range [0, UINT64_MAX_PRECISION] + * @return 10 pow n, if n is in range [0, UINT64_MAX_PRECISION]. + * Otherwise, behaviour is undefined. + */ + IGNITE_IMPORT_EXPORT uint64_t TenPowerU64(int32_t n); + + /** + * Get the signum function of the specified 64-bit integer value. + * The return value is -1 if the specified value is negative; 0 if the + * specified value is zero; and 1 if the specified value is positive. + * + * @param i the value whose signum is to be computed + * @return The signum function of the specified value. + */ + inline int32_t Signum64(int64_t i) + { + return (static_cast<uint64_t>(-i) >> 63) | (i >> 63); + } + + /** + * Makes single 64-bit integer number out of two 32-bit numbers. + * + * @param higher Higher bits part. + * @param lower Lower bits part. + * @return New 64-bit integer. + */ + inline uint64_t MakeU64(uint32_t higher, uint32_t lower) + { + return (static_cast<uint64_t>(higher) << 32) | lower; + } + + /** + * Makes single 64-bit integer number out of two 32-bit numbers. + * + * @param higher Higher bits part. + * @param lower Lower bits part. + * @return New 64-bit integer. + */ + inline int64_t MakeI64(uint32_t higher, uint32_t lower) + { + return static_cast<int64_t>(MakeU64(higher, lower)); + } + + /** + * Makes single 32-bit integer number out of two 32-bit numbers, + * shifted by specified number of bits. First number x is shifted + * to the left. + * x y + * [........][........] + * ^[........] + * n res + * + * @param x First part. + * @param y Second part. + * @param n Number of bits to shift. + * @return New 32-bit integer. + */ + inline uint32_t MakeU32(uint32_t x, uint32_t y, int32_t n) + { + return (x << n) | (y >> (32 - n)); + } + + /** + * Makes single 32-bit integer number out of two 32-bit numbers, + * shifted by specified number of bits. First number x is shifted + * to the left. + * x y + * [........][........] + * ^[........] + * n res + * + * @param x First part. + * @param y Second part. + * @param n Number of bits to shift. + * @return New 32-bit integer. + */ + inline int32_t MakeI32(uint32_t x, uint32_t y, int32_t n) + { + return static_cast<int32_t>(MakeU32(x, y, n)); + } + } + } +} + +#endif //_IGNITE_COMMON_BITS \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/ignite/common/default_allocator.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/default_allocator.h b/modules/platforms/cpp/common/include/ignite/common/default_allocator.h new file mode 100644 index 0000000..4350987 --- /dev/null +++ b/modules/platforms/cpp/common/include/ignite/common/default_allocator.h @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _IGNITE_COMMON_DEFAULT_ALLOCATOR +#define _IGNITE_COMMON_DEFAULT_ALLOCATOR + +#include <stdint.h> +#include <cstring> +#include <cassert> + +#include <utility> + +#include <ignite/common/common.h> +#include <ignite/common/fixed_size_array.h> + +namespace ignite +{ + namespace common + { + /** + * Allocator. Manages objects construction and destruction as well + * as a memory allocation. + */ + template<typename T> + class IGNITE_IMPORT_EXPORT DefaultAllocator + { + public: + typedef T ValueType; + typedef T* PointerType; + typedef T& ReferenceType; + typedef const T* ConstPointerType; + typedef const T& ConstReferenceType; + typedef int32_t SizeType; + typedef int32_t DifferenceType; + + template <class T2> struct Rebind + { + typedef DefaultAllocator<T2> other; + }; + + /** + * Default constructor. + */ + DefaultAllocator() + { + // No-op. + } + + /** + * Destructor. + */ + ~DefaultAllocator() + { + // No-op. + } + + PointerType Allocate(SizeType len, void* hint = 0) + { + return static_cast<PointerType>(::operator new(len * sizeof(ValueType))); + } + + void Deallocate(PointerType ptr, SizeType len) + { + ::operator delete(ptr); + } + + void Construct(PointerType p, ConstReferenceType val) + { + new (p) ValueType(val); + } + + void Destruct(PointerType p) + { + p->~ValueType(); + } + + private: + }; + } +} + +#endif // _IGNITE_COMMON_DEFAULT_ALLOCATOR \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/ignite/common/dynamic_size_array.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/dynamic_size_array.h b/modules/platforms/cpp/common/include/ignite/common/dynamic_size_array.h new file mode 100644 index 0000000..a6bcc13 --- /dev/null +++ b/modules/platforms/cpp/common/include/ignite/common/dynamic_size_array.h @@ -0,0 +1,415 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _IGNITE_COMMON_DYNAMIC_SIZE_ARRAY +#define _IGNITE_COMMON_DYNAMIC_SIZE_ARRAY + +#include <stdint.h> +#include <cstring> +#include <cassert> + +#include <utility> + +#include <ignite/common/common.h> +#include <ignite/common/default_allocator.h> +#include <ignite/common/bits.h> + +namespace ignite +{ + namespace common + { + /** + * Dynamic size array is safe container abstraction with a dynamic size. + * This is the analogue of the standard vector. It is needed to be used + * in exported classes as we can't export standard library classes. + */ + template<typename T, typename A = DefaultAllocator<T>> + class IGNITE_IMPORT_EXPORT DynamicSizeArray + { + public: + typedef T ValueType; + typedef A AllocatorType; + typedef typename AllocatorType::SizeType SizeType; + typedef typename AllocatorType::PointerType PointerType; + typedef typename AllocatorType::ConstPointerType ConstPointerType; + typedef typename AllocatorType::ReferenceType ReferenceType; + typedef typename AllocatorType::ConstReferenceType ConstReferenceType; + + /** + * Default constructor. + * + * Constructs zero-size and zero-capasity array. + */ + DynamicSizeArray(const AllocatorType& allocator = AllocatorType()) : + alloc(allocator), + size(0), + capasity(0), + data(0) + { + // No-op. + } + + /** + * Constructor. + * Constructs empty array with the specified capacity. + * + * @param len Array length. + * @param alloc Allocator. + */ + DynamicSizeArray(SizeType len, const AllocatorType& allocator = AllocatorType()) : + alloc(allocator), + size(0), + capasity(bits::GetCapasityForSize(len)), + data(alloc.Allocate(capasity)) + { + // No-op. + } + + /** + * Raw array constructor. + * + * @param arr Raw array. + * @param len Array length in elements. + */ + DynamicSizeArray(ConstPointerType arr, SizeType len, + const AllocatorType& allocator = AllocatorType()) : + alloc(allocator), + size(0), + capasity(0), + data(0) + { + Assign(arr, len); + } + + /** + * Copy constructor. + * + * @param other Other instance. + */ + DynamicSizeArray(const DynamicSizeArray<T>& other) : + alloc(), + size(0), + capasity(0), + data(0) + { + Assign(other); + } + + /** + * Destructor. + */ + ~DynamicSizeArray() + { + for (PointerType it = data; it != data + size; ++it) + alloc.Destruct(it); + + alloc.Deallocate(data, capasity); + } + + /** + * Assignment operator. + * + * @param other Other instance. + * @return Reference to this instance. + */ + DynamicSizeArray<T>& operator=(const DynamicSizeArray<T>& other) + { + Assign(other); + + return *this; + } + + /** + * Assign new value to the array. + * + * @param other Another array instance. + */ + void Assign(const DynamicSizeArray<T>& other) + { + if (this != &other) + { + alloc = other.alloc; + + Assign(other.GetData(), other.GetSize()); + } + } + + /** + * Assign new value to the array. + * + * @param src Raw array. + * @param len Array length in elements. + */ + void Assign(ConstPointerType src, SizeType len) + { + for (PointerType it = data; it != data + size; ++it) + alloc.Destruct(it); + + if (capasity < len) + { + alloc.Deallocate(data, capasity); + + capasity = bits::GetCapasityForSize(len); + data = alloc.Allocate(capasity); + } + + size = len; + + for (SizeType i = 0; i < size; ++i) + alloc.Construct(data + i, src[i]); + } + + /** + * Append several values to the array. + * + * @param src Raw array. + * @param len Array length in elements. + */ + void Append(ConstPointerType src, SizeType len) + { + Reserve(size + len); + + for (SizeType i = 0; i < len; ++i) + alloc.Construct(data + size + i, src[i]); + + size += len; + } + + /** + * Swap contents of the array with another instance. + * + * @param other Instance to swap with. + */ + void Swap(DynamicSizeArray<T>& other) + { + if (this != &other) + { + std::swap(alloc, other.alloc); + std::swap(size, other.size); + std::swap(capasity, other.capasity); + std::swap(data, other.data); + } + } + + /** + * Get data pointer. + * + * @return Data pointer. + */ + PointerType GetData() + { + return data; + } + + /** + * Get data pointer. + * + * @return Data pointer. + */ + ConstPointerType GetData() const + { + return data; + } + + /** + * Get array size. + * + * @return Array size. + */ + SizeType GetSize() const + { + return size; + } + + /** + * Get capasity. + * + * @return Array capasity. + */ + SizeType GetCapasity() const + { + return capasity; + } + + /** + * Element access operator. + * + * @param idx Element index. + * @return Element reference. + */ + ReferenceType operator[](SizeType idx) + { + assert(idx < size); + + return data[idx]; + } + + /** + * Element access operator. + * + * @param idx Element index. + * @return Element reference. + */ + ConstReferenceType operator[](SizeType idx) const + { + assert(idx < size); + + return data[idx]; + } + + /** + * Check if the array is empty. + * + * @return True if the array is empty. + */ + bool IsEmpty() const + { + return size == 0; + } + + /** + * Clears the array. + */ + void Clear() + { + for (PointerType it = data; it != data + size; ++it) + alloc.Destruct(it); + + size = 0; + } + + /** + * Reserves not less than specified elements number so array is not + * going to grow on append. + * + * @param newCapacity Desired capasity. + */ + void Reserve(SizeType newCapacity) + { + if (capasity < newCapacity) + { + DynamicSizeArray<T> tmp(newCapacity); + + tmp.Assign(*this); + + Swap(tmp); + } + } + + /** + * Resizes array. Destructs elements if the specified size is less + * than the array's size. Default-constructs elements if the + * specified size is more than the array's size. + * + * @param newSize Desired size. + */ + void Resize(SizeType newSize) + { + if (capasity < newSize) + Reserve(newSize); + + if (newSize > size) + { + for (PointerType it = data + size; it < data + newSize; ++it) + alloc.Construct(it, ValueType()); + } + else + { + for (PointerType it = data + newSize; it < data + size; ++it) + alloc.Destruct(it); + } + + size = newSize; + } + + /** + * Get last element. + * + * @return Last element reference. + */ + const ValueType& Back() const + { + assert(size > 0); + + return data[size - 1]; + } + + /** + * Get last element. + * + * @return Last element reference. + */ + ValueType& Back() + { + assert(size > 0); + + return data[size - 1]; + } + + /** + * Get first element. + * + * @return First element reference. + */ + const ValueType& Front() const + { + assert(size > 0); + + return data[0]; + } + + /** + * Get first element. + * + * @return First element reference. + */ + ValueType& Front() + { + assert(size > 0); + + return data[0]; + } + + /** + * Pushes new value to the back of the array, effectively increasing + * array size by one. + * + * @param val Value to push. + */ + void PushBack(ConstReferenceType val) + { + Resize(size + 1); + + Back() = val; + } + + private: + /** Allocator */ + AllocatorType alloc; + + /** Array size. */ + SizeType size; + + /** Array capasity. */ + SizeType capasity; + + /** Data. */ + PointerType data; + }; + } +} + +#endif // _IGNITE_COMMON_DYNAMIC_SIZE_ARRAY \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/ignite/common/fixed_size_array.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/fixed_size_array.h b/modules/platforms/cpp/common/include/ignite/common/fixed_size_array.h new file mode 100644 index 0000000..4e102e6 --- /dev/null +++ b/modules/platforms/cpp/common/include/ignite/common/fixed_size_array.h @@ -0,0 +1,288 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _IGNITE_COMMON_FIXED_SIZE_ARRAY +#define _IGNITE_COMMON_FIXED_SIZE_ARRAY + +#include <stdint.h> +#include <cstring> +#include <cassert> + +#include <utility> +#include <algorithm> + +#include <ignite/common/common.h> + +namespace ignite +{ + namespace common + { + /** + * Fixed size array is safe array abstraction with a fixed size. + * The size can be set during runtime though once array is created + * its size can not be changed without resetting arrays content. + */ + template<typename T> + class IGNITE_IMPORT_EXPORT FixedSizeArray + { + public: + typedef int32_t SizeType; + + /** + * Default constructor. + * + * Constructs zero-size array. + */ + FixedSizeArray() : + size(0), + data(0) + { + // No-op. + } + + /** + * Constructor. + * Constructs default-initialized array of the specified length. + * Array zeroed if T is a POD type. + * + * @param len Array length. + */ + FixedSizeArray(SizeType len) : + size(len), + // Brackets are here for a purpose - this way allocated + // array is zeroed if T is POD type. + data(new T[size]()) + { + // No-op. + } + + /** + * Copy constructor. + * + * @param other Other instance. + */ + FixedSizeArray(const FixedSizeArray<T>& other) : + size(other.size), + data(new T[size]) + { + Assign(other); + } + + /** + * Raw array constructor. + * + * @param arr Raw array. + * @param len Array length in elements. + */ + FixedSizeArray(const T* arr, SizeType len) : + size(len), + data(new T[size]) + { + Assign(arr, len); + } + + /** + * Assignment operator. + * + * @param other Other instance. + * @return Reference to this instance. + */ + FixedSizeArray<T>& operator=(const FixedSizeArray<T>& other) + { + Assign(other); + + return *this; + } + + /** + * Assign new value to the array. + * + * @param other Another array instance. + */ + void Assign(const FixedSizeArray<T>& other) + { + if (this != &other) + Assign(other.GetData(), other.GetSize()); + } + + /** + * Assign new value to the array. + * + * @param src Raw array. + * @param len Array length in elements. + */ + void Assign(const T* src, SizeType len) + { + // In case we would not need to clean anything + // its okay to call delete[] on 0. + T* toClean = 0; + + if (len != size) + { + // Do not clean just yet in case the part of the + // array is being assigned to the array. + toClean = data; + + size = len; + data = new T[size]; + } + + for (SizeType i = 0; i < len; ++i) + data[i] = src[i]; + + delete[] toClean; + } + + /** + * Swap contents of the array with another instance. + * + * @param other Instance to swap with. + */ + void Swap(FixedSizeArray<T>& other) + { + if (this != &other) + { + std::swap(size, other.size); + std::swap(data, other.data); + } + } + + /** + * Destructor. + */ + ~FixedSizeArray() + { + // Not a bug. Delete works just fine on null pointers. + delete[] data; + } + + /** + * Get data pointer. + * + * @return Data pointer. + */ + T* GetData() + { + return data; + } + + /** + * Get data pointer. + * + * @return Data pointer. + */ + const T* GetData() const + { + return data; + } + + /** + * Get array size. + * + * @return Array size. + */ + SizeType GetSize() const + { + return size; + } + + /** + * Copy part of the array and place in another array. + * Contents of the provided array gets swapped with the copy of the + * specified array part. + * + * @param pos Start position. + * @param n Number of elements to copy. + * @param result Instance of an array where result should be placed. + */ + void CopyPart(SizeType pos, SizeType n, FixedSizeArray<T>& result) const + { + assert(pos < size); + assert(pos + n <= size); + + result.Assign(data + pos, n); + } + + /** + * Element access operator. + * + * @param idx Element index. + * @return Element reference. + */ + T& operator[](SizeType idx) + { + assert(idx < size); + + return data[idx]; + } + + /** + * Element access operator. + * + * @param idx Element index. + * @return Element reference. + */ + const T& operator[](SizeType idx) const + { + assert(idx < size); + + return data[idx]; + } + + /** + * Check if the array is empty. + * + * @return True if the array is empty. + */ + bool IsEmpty() const + { + return size == 0; + } + + /** + * Resets the state of the array setting it to the specified size + * and erasing its content. + * + * @param newSize New array size. + */ + void Reset(SizeType newSize = 0) + { + if (size != newSize) + { + delete[] data; + + if (newSize) + data = new T[newSize](); + else + data = 0; + + size = newSize; + } + else + std::fill(data, data + size, T()); + } + + private: + /** Array size. */ + SizeType size; + + /** Target array. */ + T* data; + }; + } +} + +#endif // _IGNITE_COMMON_FIXED_SIZE_ARRAY \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/ignite/common/utils.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/utils.h b/modules/platforms/cpp/common/include/ignite/common/utils.h index ff6905d..c1046e2 100644 --- a/modules/platforms/cpp/common/include/ignite/common/utils.h +++ b/modules/platforms/cpp/common/include/ignite/common/utils.h @@ -118,36 +118,6 @@ namespace ignite IGNITE_IMPORT_EXPORT bool IgniteLocalTime(time_t in, tm& out); /** - * Get number of leading zeroes in octet. - * - * @param octet Octet. - * @return Number of leading zero-bits. - */ - IGNITE_IMPORT_EXPORT int LeadingZeroesForOctet(int8_t octet); - - /** - * Get number of significant bits in octet. - * - * @param octet Octet. - * @return Number of significant bits. - */ - inline int BitLengthForOctet(int8_t octet) - { - return 8 - LeadingZeroesForOctet(octet); - } - - /** - * Check if the number is power of two. - * - * @param num Integer number. - * @return True if the number is power of two. - */ - inline bool PowerOfTwo(int num) - { - return (num & (num - 1)) == 0; - } - - /** * Copy characters. * * @param val Value. @@ -180,32 +150,35 @@ namespace ignite IGNITE_IMPORT_EXPORT bool FileExists(const std::string& path); /** - * Safe array which automatically reclaims occupied memory when out of scope. + * Casts value of one type to another type, using stringstream. + * + * @param val Input value. + * @param res Resulted value. + */ + template<typename T1, typename T2> + void LexicalCast(const T2& val, T1& res) + { + std::stringstream converter; + + converter << val; + converter >> res; + } + + /** + * Casts value of one type to another type, using stringstream. + * + * @param val Input value. + * @return Resulted value. */ - template<typename T> - struct IGNITE_IMPORT_EXPORT SafeArray + template<typename T1, typename T2> + T1 LexicalCast(const T2& val) { - /** Target array. */ - T* target; - - /** - * Constructor. - */ - SafeArray(int cap) - { - target = new T[cap]; - } - - /** - * Destructor. - */ - ~SafeArray() - { - delete[] target; - } - - IGNITE_NO_COPY_ASSIGNMENT(SafeArray); - }; + T1 res; + + LexicalCast<T1, T2>(val, res); + + return res; + } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/include/ignite/guid.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/guid.h b/modules/platforms/cpp/common/include/ignite/guid.h index 9a045e6..fbafd5c 100644 --- a/modules/platforms/cpp/common/include/ignite/guid.h +++ b/modules/platforms/cpp/common/include/ignite/guid.h @@ -122,7 +122,7 @@ namespace ignite * @return Reference to the first param. */ template<typename C> - std::basic_ostream<C>& operator<<(std::basic_ostream<C>& os, const Guid& guid) + ::std::basic_ostream<C>& operator<<(std::basic_ostream<C>& os, const Guid& guid) { uint32_t part1 = static_cast<uint32_t>(guid.GetMostSignificantBits() >> 32); uint16_t part2 = static_cast<uint16_t>(guid.GetMostSignificantBits() >> 16); @@ -147,7 +147,7 @@ namespace ignite * @return Reference to the first param. */ template<typename C> - std::basic_istream<C>& operator>>(std::basic_istream<C>& is, Guid& guid) + ::std::basic_istream<C>& operator>>(std::basic_istream<C>& is, Guid& guid) { uint64_t parts[5]; http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/os/win/src/common/utils.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/win/src/common/utils.cpp b/modules/platforms/cpp/common/os/win/src/common/utils.cpp index 65236d2..47d7f43 100644 --- a/modules/platforms/cpp/common/os/win/src/common/utils.cpp +++ b/modules/platforms/cpp/common/os/win/src/common/utils.cpp @@ -64,27 +64,6 @@ namespace ignite return localtime_s(&out, &in) == 0; } - int LeadingZeroesForOctet(int8_t octet) { - if (octet == 0) - return 8; - - int zeroes = 1; - - if (octet >> 4 == 0) { - zeroes += 4; - octet <<= 4; - } - - if (octet >> 6 == 0) { - zeroes += 2; - octet <<= 2; - } - - zeroes -= octet >> 7; - - return zeroes; - } - char* CopyChars(const char* val) { if (val) { http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/project/vs/common.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/common.vcxproj b/modules/platforms/cpp/common/project/vs/common.vcxproj index 67f01ff..e0abed2 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj @@ -95,7 +95,7 @@ <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> - <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> @@ -111,7 +111,7 @@ <WarningLevel>Level3</WarningLevel> <SDLCheck>false</SDLCheck> <AdditionalIncludeDirectories>$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> </ClCompile> <Link> @@ -128,7 +128,7 @@ <Optimization>MaxSpeed</Optimization> <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> - <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> @@ -156,7 +156,7 @@ <OmitFramePointers>true</OmitFramePointers> <StringPooling>true</StringPooling> <BufferSecurityCheck>false</BufferSecurityCheck> - <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> <GenerateDebugInformation>true</GenerateDebugInformation> @@ -165,7 +165,13 @@ </Link> </ItemDefinitionGroup> <ItemGroup> + <ClInclude Include="..\..\include\ignite\common\big_integer.h" /> <ClInclude Include="..\..\include\ignite\common\concurrent.h" /> + <ClInclude Include="..\..\include\ignite\common\decimal.h" /> + <ClInclude Include="..\..\include\ignite\common\default_allocator.h" /> + <ClInclude Include="..\..\include\ignite\common\dynamic_size_array.h" /> + <ClInclude Include="..\..\include\ignite\common\fixed_size_array.h" /> + <ClInclude Include="..\..\include\ignite\common\bits.h" /> <ClInclude Include="..\..\include\ignite\common\utils.h" /> <ClInclude Include="..\..\include\ignite\date.h" /> <ClInclude Include="..\..\include\ignite\guid.h" /> @@ -178,7 +184,10 @@ <ItemGroup> <ClCompile Include="..\..\os\win\src\common\concurrent_os.cpp" /> <ClCompile Include="..\..\os\win\src\common\utils.cpp" /> + <ClCompile Include="..\..\src\common\big_integer.cpp" /> + <ClCompile Include="..\..\src\common\bits.cpp" /> <ClCompile Include="..\..\src\common\concurrent.cpp" /> + <ClCompile Include="..\..\src\common\decimal.cpp" /> <ClCompile Include="..\..\src\date.cpp" /> <ClCompile Include="..\..\src\guid.cpp" /> <ClCompile Include="..\..\src\ignite_error.cpp" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/5cc1f074/modules/platforms/cpp/common/project/vs/common.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/common.vcxproj.filters b/modules/platforms/cpp/common/project/vs/common.vcxproj.filters index 1a6f069..ae17daf 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj.filters +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj.filters @@ -40,6 +40,24 @@ <ClInclude Include="..\..\include\ignite\ignite_error.h"> <Filter>Code</Filter> </ClInclude> + <ClInclude Include="..\..\include\ignite\common\fixed_size_array.h"> + <Filter>Code\common</Filter> + </ClInclude> + <ClInclude Include="..\..\include\ignite\common\big_integer.h"> + <Filter>Code\common</Filter> + </ClInclude> + <ClInclude Include="..\..\include\ignite\common\dynamic_size_array.h"> + <Filter>Code\common</Filter> + </ClInclude> + <ClInclude Include="..\..\include\ignite\common\default_allocator.h"> + <Filter>Code\common</Filter> + </ClInclude> + <ClInclude Include="..\..\include\ignite\common\bits.h"> + <Filter>Code\common</Filter> + </ClInclude> + <ClInclude Include="..\..\include\ignite\common\decimal.h"> + <Filter>Code\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\src\date.cpp"> @@ -63,5 +81,14 @@ <ClCompile Include="..\..\src\ignite_error.cpp"> <Filter>Code</Filter> </ClCompile> + <ClCompile Include="..\..\src\common\big_integer.cpp"> + <Filter>Code\common</Filter> + </ClCompile> + <ClCompile Include="..\..\src\common\decimal.cpp"> + <Filter>Code\common</Filter> + </ClCompile> + <ClCompile Include="..\..\src\common\bits.cpp"> + <Filter>Code\common</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file
