Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C4823200B8D for ; Thu, 8 Sep 2016 17:40:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C1829160AD0; Thu, 8 Sep 2016 15:40:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8FF98160ADF for ; Thu, 8 Sep 2016 17:40:46 +0200 (CEST) Received: (qmail 81797 invoked by uid 500); 8 Sep 2016 15:40:45 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 80762 invoked by uid 99); 8 Sep 2016 15:40:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Sep 2016 15:40:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 35D3EE08B7; Thu, 8 Sep 2016 15:40:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Thu, 08 Sep 2016 15:41:19 -0000 Message-Id: <3b9532e9136e492aa56d00ca6dbc2b27@git.apache.org> In-Reply-To: <1b11fdb4ca024595b5ebcd8933780c53@git.apache.org> References: <1b11fdb4ca024595b5ebcd8933780c53@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [37/50] [abbrv] ignite git commit: IGNITE-3390: Added DSN configuration window. archived-at: Thu, 08 Sep 2016 15:40:47 -0000 http://git-wip-us.apache.org/repos/asf/ignite/blob/70e69cb7/modules/platforms/cpp/odbc/src/protocol_version.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/src/protocol_version.cpp b/modules/platforms/cpp/odbc/src/protocol_version.cpp new file mode 100644 index 0000000..818df88 --- /dev/null +++ b/modules/platforms/cpp/odbc/src/protocol_version.cpp @@ -0,0 +1,131 @@ +/* + * 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. + */ +#include +#include +#include + +#include "ignite/odbc/protocol_version.h" +#include "ignite/odbc/utility.h" + +namespace ignite +{ + namespace odbc + { + const ProtocolVersion ProtocolVersion::VERSION_1_6_0(1); + const ProtocolVersion ProtocolVersion::VERSION_UNKNOWN(INT64_MIN); + + ProtocolVersion::StringToVersionMap::value_type s2vInitVals[] = { + std::make_pair("1.6.0", ProtocolVersion::VERSION_1_6_0) + }; + + const ProtocolVersion::StringToVersionMap ProtocolVersion::stringToVersionMap(s2vInitVals, + s2vInitVals + (sizeof(s2vInitVals) / sizeof(s2vInitVals[0]))); + + ProtocolVersion::VersionToStringMap::value_type v2sInitVals[] = { + std::make_pair(ProtocolVersion::VERSION_1_6_0, "1.6.0") + }; + + const ProtocolVersion::VersionToStringMap ProtocolVersion::versionToStringMap(v2sInitVals, + v2sInitVals + (sizeof(v2sInitVals) / sizeof(v2sInitVals[0]))); + + ProtocolVersion::ProtocolVersion(int64_t val) : + val(val) + { + // No-op. + } + + const ProtocolVersion::StringToVersionMap& ProtocolVersion::GetMap() + { + return stringToVersionMap; + } + + const ProtocolVersion& ProtocolVersion::GetCurrent() + { + return VERSION_1_6_0; + } + + ProtocolVersion ProtocolVersion::FromString(const std::string& version) + { + StringToVersionMap::const_iterator it = stringToVersionMap.find(common::ToLower(version)); + + if (it == stringToVersionMap.end()) + { + throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, + "Invalid version format. Valid format is X.Y.Z, where X, Y and Z are major " + "and minor versions and revision of Ignite since which protocol is introduced."); + } + + return it->second; + } + + const std::string& ProtocolVersion::ToString() const + { + VersionToStringMap::const_iterator it = versionToStringMap.find(*this); + + if (it == versionToStringMap.end()) + { + throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, + "Unknown protocol version can not be converted to string."); + } + + return it->second; + } + + int64_t ProtocolVersion::GetIntValue() const + { + assert(!IsUnknown()); + + return val; + } + + bool ProtocolVersion::IsUnknown() const + { + return *this == VERSION_UNKNOWN; + } + + bool operator==(const ProtocolVersion& val1, const ProtocolVersion& val2) + { + return val1.val == val2.val; + } + + bool operator!=(const ProtocolVersion& val1, const ProtocolVersion& val2) + { + return val1.val != val2.val; + } + + bool operator<(const ProtocolVersion& val1, const ProtocolVersion& val2) + { + return val1.val < val2.val; + } + + bool operator<=(const ProtocolVersion& val1, const ProtocolVersion& val2) + { + return val1.val <= val2.val; + } + + bool operator>(const ProtocolVersion& val1, const ProtocolVersion& val2) + { + return val1.val > val2.val; + } + + bool operator>=(const ProtocolVersion& val1, const ProtocolVersion& val2) + { + return val1.val >= val2.val; + } + } +} +