#include "stdafx.h"
#include <algorithm>		// For find template.
#include "UtilSort.h"		// This header.

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FFAddSortOrder
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfMiBfLiDgHiCmMiPiHjEnEiCpAiOkGiClHjEhKjHpBiCpAiNfMjAkMiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	vSortOrder	:_xZkqqHx_iDfMiBfLiDgHiPiHjEhKjHpBiCpAjFnEiClHiBeC_xHqqkZx_
 *			wItem		:_xZkqqHx_iDfMiBfLiDgHiPiHiCmMiDgHiDgCiDhGiCmJjCmHiJmBiClHiCoJiDeBiDeDiDgFiDiAiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_iOhHjCoIiCmMiDeBiDeDiDgFiDiAiCpAiBeBiDfMiBfLiDgHiPiHiCmMiDgHiDgCiDhGiCmJjAjIiCkGiCoJiBeCjDkPiClGiDeBiDeDiDgFiDiAiCkK_xHqqkZx_
 *			_xZkqqHx_iKpJiCmJiDgHiDgCiDhGiCmJiCkAiCoJiPoKiNiHiCmNiBeBiDiKiDgPiBfLiDfIiCmJjFmPiNfIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.04.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FFAddSortOrder (WORDVector& vSortOrder, WORD wItem)
{
	if (vSortOrder.empty())
	{
		vSortOrder.push_back(wItem);
	} else
	if (vSortOrder.back() == wItem)
	{
		vSortOrder.back() |= 0x8000;
	} else
	{
		// _xZkqqHx_iOhHjCoIiCmMiDeBiDeDiDgFiDiAiCkKjCoBiImKiCmMiDfMiBfLiDgHiPiHiCmJiCkAiCoJiPoKiNiHiCmNiOoGiCoIiPjMiCkNiBeC_xHqqkZx_
		WORD wRItem = wItem | 0x8000;
		WORDVector::iterator iR;
		iR = find(vSortOrder.begin(), vSortOrder.end(), wItem);
		if (iR != vSortOrder.end()) vSortOrder.erase(iR);
		iR = find(vSortOrder.begin(), vSortOrder.end(), wRItem);
		if (iR != vSortOrder.end()) vSortOrder.erase(iR);
		// _xZkqqHx_iDfMiBfLiDgHiPiHiDgHiDgCiDhGiCmJjAnNjCoIiBeC_xHqqkZx_
		vSortOrder.push_back(wItem);
	}
} // FFAddSortOrder.

