STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem > Class Template Reference

#include <diff_tool.h>


Detailed Description

template<class ItemType, class Context, class GetIdentifier = TGetIdentifier<ItemType>, class GetHashValue = TGetHashValue<ItemType>, class TestItem = TTestItem<ItemType>>
class STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem >

ItemType must have a property named Identifier that uniquely identify each item. ItemType must have a property named HashValue that is used to determine the change between context.Addition and context.Reference vector.

Definition at line 374 of file diff_tool.h.

Public Member Functions

void makeDiff (IDiffCallback *callback, Context &context, bool skipFirstRecord=false)


Member Function Documentation

template<class ItemType, class Context, class GetIdentifier = TGetIdentifier<ItemType>, class GetHashValue = TGetHashValue<ItemType>, class TestItem = TTestItem<ItemType>>
void STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem >::makeDiff IDiffCallback callback,
Context &  context,
bool  skipFirstRecord = false
[inline]
 

Definition at line 387 of file diff_tool.h.

References index, STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem >::IDiffCallback::onAdd(), STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem >::IDiffCallback::onChanged(), STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem >::IDiffCallback::onEquivalent(), STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem >::IDiffCallback::onRemove(), STRING_MANAGER::CMakeDiff< ItemType, Context, GetIdentifier, GetHashValue, TestItem >::IDiffCallback::onSwap(), and uint.

00388                 {
00389 #ifdef NL_DEBUG
00390                         // compile time checking
00391 //                      Context::iterator testIt;
00392 #endif
00393                         GetIdentifier   getIdentifier;
00394                         GetHashValue    getHashValue;
00395                         // compare the context.Reference an context.Addition file, remove any equivalent strings.
00396                         uint addCount, refCount;
00397                         if (skipFirstRecord)
00398                         {
00399                                 addCount = 1;
00400                                 refCount = 1;
00401                         }
00402                         else
00403                         {
00404                                 addCount = 0; 
00405                                 refCount=0;
00406                         }
00407 
00408                         while (addCount < context.Addition.size() || refCount < context.Reference.size())
00409                         {
00410                                 bool equal = true;
00411                                 if (addCount != context.Addition.size() && refCount != context.Reference.size())
00412                                 {
00413                                         equal = getHashValue(context.Addition, addCount) == getHashValue(context.Reference, refCount);
00414                                 }
00415 
00416 //                              vector<ItemType>::iterator it;
00417 
00418                                 if (addCount == context.Addition.size()
00419                                         || 
00420                                                 (
00421                                                         !equal
00422                                                 &&      find_if(context.Addition.begin(), context.Addition.end(), TestItem(getIdentifier(context.Reference, refCount))) == context.Addition.end()
00423                                                 )
00424                                         )
00425                                 {       
00426                                         // this can only be removal
00427                                         callback->onRemove(addCount, refCount, context);
00428                                         context.Reference.erase(context.Reference.begin()+refCount);
00429 //                                      ++refCount;
00430                                 }
00431                                 else if (refCount == context.Reference.size()
00432                                         || 
00433                                                 (
00434                                                         !equal
00435                                                 &&      find_if(context.Reference.begin(), context.Reference.end(), TestItem(getIdentifier(context.Addition, addCount))) == context.Reference.end()
00436                                                 )
00437                                         )
00438                                 {
00439                                         // this can only be context.Addition
00440                                         callback->onAdd(addCount, refCount, context);
00441                                         context.Reference.insert(context.Reference.begin()+refCount, context.Addition[addCount]);
00442                                         ++refCount;
00443                                         ++addCount;
00444                                 }
00445                                 else if (getIdentifier(context.Addition, addCount) != getIdentifier(context.Reference, refCount))
00446                                 {
00447                                         // swap two element.
00448 //                                      Context::iterator it = find_if(context.Reference.begin(), context.Reference.end(), TestItem(getIdentifier(context.Addition, addCount)));
00449 //                                      if (it == context.Reference.end())
00450 
00451                                         if (find_if(
00452                                                         context.Reference.begin(), 
00453                                                         context.Reference.end(), 
00454                                                         TestItem(getIdentifier(context.Addition, addCount)))
00455                                                         == context.Reference.end())
00456                                         {
00457                                                 // context.Addition
00458                                                 callback->onAdd(addCount, refCount, context);
00459                                                 context.Reference.insert(context.Reference.begin()+refCount, context.Addition[addCount]);
00460                                                 ++refCount;
00461                                                 ++addCount;
00462                                         }
00463                                         else
00464                                         {
00465 //                                              nlassert(it != context.Reference.begin()+refCount);
00466                                                 uint index = find_if(context.Reference.begin(), context.Reference.end(), TestItem(getIdentifier(context.Addition, addCount))) - context.Reference.begin();
00467 
00468 //                                              callback->onSwap(it - context.Reference.begin(), refCount, context);
00469                                                 callback->onSwap(index, refCount, context);
00470 //                                              swap(*it, context.Reference[refCount]);
00471                                                 swap(context.Reference[index], context.Reference[refCount]);
00472                                         }
00473                                 }
00474                                 else if (getHashValue(context.Addition, addCount) != getHashValue(context.Reference, refCount))
00475                                 {
00476                                         // changed element
00477                                         callback->onChanged(addCount, refCount, context);
00478                                         ++refCount;
00479                                         ++addCount;
00480                                 }
00481                                 else
00482                                 {
00483                                         // same entry
00484                                         callback->onEquivalent(addCount, refCount, context);
00485                                         addCount++;
00486                                         refCount++;
00487                                 }
00488                         }
00489                 }


The documentation for this class was generated from the following file:
Generated on Tue Mar 16 14:54:13 2004 for NeL by doxygen 1.3.6