// Note: Instrumentation statements are highlighted in green

#include "NameInfo.hpp"
#include "string_io.hpp"

///////////////////////////////////////////////////////////////////////////////
// NameInfo class
///////////////////////////////////////////////////////////////////////////////

// Visual Member Definition
VISIBILITY_START(NameInfo, "Name Info.", 2)
VVARIABLE(NameInfo, first, "First", 0, 0)
VVARIABLE(NameInfo, middle, "Middle", 0, 0)
VVARIABLE(NameInfo, last, "Last", 0, 0)
VVARIABLE(NameInfo, title, "Title", 0, 0)
VVARIABLE(NameInfo, nickName, "Nickname", 0, 0)
VVARIABLE(NameInfo, displayName, "Display name", 0, 0)
VBITSET_VARIABLE(NameInfo, displayFormat, DisplayFormat, "Display", 0, 0)
VCHARPTR_FUNCTION(NameInfo, createDisplayName, "Create display name", 0, 0)
VVOID_FUNCTION(NameInfo, clear, "Clear", 0, 0)
VISIBILITY_END

NameInfo::NameInfo(void) :
  displayFormat(FIRST)
{
}

NameInfo::NameInfo(const NameInfo & that)
{
  *this = that;
}

NameInfo::~NameInfo(void)
{
}

NameInfo & NameInfo::operator =(const NameInfo & that)
{
  if (this != &that) {
    first = that.first;
    middle = that.middle;
    last = that.last;
    title = that.title;
    nickName = that.nickName;
    displayFormat = that.displayFormat;
    displayName = that.displayName;
  }
  return *this;
}

std::ostream & operator<< (std::ostream& os, NameInfo & out_obj)
{
  write_string(os, out_obj.first);
  write_string(os, out_obj.middle);
  write_string(os, out_obj.last);
  write_string(os, out_obj.title);
  write_string(os, out_obj.nickName);
  os << out_obj.displayFormat << " ";
  return os;
}

std::istream & operator>> (std::istream & is, NameInfo & in_obj)
{
  read_string(is, in_obj.first);
  read_string(is, in_obj.middle);
  read_string(is, in_obj.last);
  read_string(is, in_obj.title);
  read_string(is, in_obj.nickName);
  is >> in_obj.displayFormat;
  return is;
}

bool NameInfo::operator==(const NameInfo & that) const
{
  return last == that.last;
}

bool NameInfo::operator!=(const NameInfo & that) const
{
  return last != that.last;
}

bool NameInfo::operator<(const NameInfo & that) const
{
  return last < that.last;
}

bool NameInfo::operator>(const NameInfo & that) const
{
  return last > that.last;
}

char * NameInfo::createDisplayName(void)
{
  std::string temp_name;
  switch (displayFormat)
  {
    case FIRST:
      temp_name = first;
      break;

    case FIRST_MIDDLE_LAST :
      temp_name = first;
      if (middle.length())
        temp_name += " " + middle;
      temp_name += " " + last;
      break;

    case LAST_FIRST_MIDDLE :
      temp_name = last;
      temp_name += " ";
      temp_name += first;
      if (middle.length()) {
        temp_name += " "; 
        temp_name += middle;
      }
      break;

    case LAST_COMMA_FIRST_MIDDLE :
      temp_name = last + ", " + first + " ";
      if (middle.length())
        temp_name += " " + middle;
      break;

    case NICKNAME:
      temp_name = nickName;
      break;

  }
  displayName = temp_name;
  return const_cast<char *>(displayName.c_str());
}

void NameInfo::clear(void)
{
  first = "";
  middle = "";
  last = "";
  title = "";
  nickName =  "";
}

void NameInfo::populateEditView(void)
{
  first = "Jack";
  middle = "Frank";
  last = "Sprat";
  title = "Mr.";
  nickName =  "Jackie";
}


Copyright 2002-2007 Outerface Technologies, Inc.