text: /*
   * 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_EXAMPLES_PERSON
  #define _IGNITE_EXAMPLES_PERSON
  
  #include <string>
  #include <sstream>
  
  #include "ignite/ignite.h"
  #include "ignite/ignition.h"
  
  namespace ignite
  {
      namespace examples
      {
          struct Person
          {
              Person() : orgId(0), salary(.0)
              {
                  // No-op.
              }
  
              Person(int64_t orgId, const std::string& firstName,
                  const std::string& lastName, const std::string& resume, double salary) :
                  orgId(orgId),
                  firstName(firstName),
                  lastName(lastName),
                  resume(resume),
                  salary(salary)
              {
                  // No-op.
              }
  
              std::string ToString() const
              {
                  std::ostringstream oss;
  
                  oss << "Person [orgId=" << orgId
                      << ", lastName=" << lastName
                      << ", firstName=" << firstName
                      << ", salary=" << salary
                      << ", resume=" << resume << ']';
  
                  return oss.str();
              }
  
              int64_t orgId;
              std::string firstName;
              std::string lastName;
              std::string resume;
              double salary;
          };
  
          // Person key with affinity Organization info. If we want to to collocate Persons with the same value of orgId
          // we need to put struct as a cache key that contains fields: 1) id of the record (person id or serial id number)
          // 2) collocation column info (orgId). This is required because of constraint : affinity key must be part of the
          // key.
          struct PersonKey {
              PersonKey(int64_t _id, int64_t _orgId) : id(_id), orgIdAff(_id)
              {
                  // No-op.
              }
  
              PersonKey() : id(0), orgIdAff(0)
              {
                  // No-op.
              }
  
              std::string ToString() const
              {
                  std::ostringstream oss;
  
                  oss << "PersonKey [id=" << id
                      << ", orgIdAff=" << orgIdAff
                      << "]";
                  return oss.str();
              }
  
              int64_t  id;
              int64_t  orgIdAff;
          };
      }
  }
  
  namespace ignite
  {
      namespace binary
      {
          IGNITE_BINARY_TYPE_START(ignite::examples::Person)
  
              typedef ignite::examples::Person Person;
  
              IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Person)
              IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Person)
              IGNITE_BINARY_GET_FIELD_ID_AS_HASH
              IGNITE_BINARY_IS_NULL_FALSE(Person)
              IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Person)
  
              static void Write(BinaryWriter& writer, const ignite::examples::Person& obj)
              {
                  writer.WriteInt64("orgId", obj.orgId);
                  writer.WriteString("firstName", obj.firstName);
                  writer.WriteString("lastName", obj.lastName);
                  writer.WriteString("resume", obj.resume);
                  writer.WriteDouble("salary", obj.salary);
              }
  
              static void Read(BinaryReader& reader, ignite::examples::Person& dst)
              {
                  dst.orgId = reader.ReadInt64("orgId");
                  dst.firstName = reader.ReadString("firstName");
                  dst.lastName = reader.ReadString("lastName");
                  dst.resume = reader.ReadString("resume");
                  dst.salary = reader.ReadDouble("salary");
              }
  
          IGNITE_BINARY_TYPE_END
  
          IGNITE_BINARY_TYPE_START(ignite::examples::PersonKey)
  
              typedef ignite::examples::PersonKey PersonKey;
  
              IGNITE_BINARY_GET_TYPE_ID_AS_HASH(PersonKey)
              IGNITE_BINARY_GET_TYPE_NAME_AS_IS(PersonKey)
              IGNITE_BINARY_GET_FIELD_ID_AS_HASH
              IGNITE_BINARY_IS_NULL_FALSE(PersonKey)
              IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(PersonKey)
  
              static void Write(BinaryWriter& writer, const ignite::examples::PersonKey& obj)
              {
                  writer.WriteInt64("id", obj.id);
                  writer.WriteInt64("orgIdAff", obj.orgIdAff);
              }
  
              static void Read(BinaryReader& reader, ignite::examples::PersonKey& dst)
              {
                  dst.id = reader.ReadInt64("id");
                  dst.orgIdAff = reader.ReadInt64("orgIdAff");
              }
  
          IGNITE_BINARY_TYPE_END
      }
  };
  
  #endif // _IGNITE_EXAMPLES_PERSON