secureswitools/swisistools/source/sisxlibrary/sisversion.cpp
changeset 0 ba25891c3a9e
child 26 04d4a7bbc3e0
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Note: This file may contain code to generate corrupt files for test purposes.
       
    16 * Such code is excluded from production builds by use of compiler defines;
       
    17 * it is recommended that such code should be removed if this code is ever published publicly.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 /**
       
    23  @file 
       
    24  @internalComponent
       
    25  @released
       
    26 */
       
    27 
       
    28 #include "sisversion.h"
       
    29 #include "exception.h"
       
    30 
       
    31 
       
    32 CSISVersion::CSISVersion (const bool aRequired) :
       
    33 		CStructure <CSISFieldRoot::ESISVersion> (aRequired),
       
    34 		iPermitAny (false),
       
    35 		iMajor (KIrrelevant), 
       
    36 		iMinor (KIrrelevant), 
       
    37 		iBuild (KIrrelevant)
       
    38 	{ 
       
    39 	InsertMembers (); 
       
    40 	}
       
    41 
       
    42 
       
    43 CSISVersion::CSISVersion (const bool aRequired, const bool aPermitAny) :
       
    44 		CStructure <CSISFieldRoot::ESISVersion> (aRequired),
       
    45 		iPermitAny (aPermitAny),
       
    46 		iMajor (KIrrelevant), 
       
    47 		iMinor (KIrrelevant), 
       
    48 		iBuild (KIrrelevant)
       
    49 	{ 
       
    50 	InsertMembers (); 
       
    51 	}
       
    52 
       
    53 
       
    54 CSISVersion::CSISVersion (const CSISVersion& aInitialiser) :
       
    55 		CStructure <CSISFieldRoot::ESISVersion> (aInitialiser),
       
    56 		iPermitAny (aInitialiser.iPermitAny),
       
    57 		iMajor (aInitialiser.iMajor), 
       
    58 		iMinor (aInitialiser.iMinor), 
       
    59 		iBuild (aInitialiser.iBuild)
       
    60 	{ 
       
    61 	InsertMembers (); 
       
    62 	}
       
    63 
       
    64 
       
    65 void CSISVersion::InsertMembers ()
       
    66 	{
       
    67 	InsertMember (iMajor);
       
    68 	InsertMember (iMinor);
       
    69 	InsertMember (iBuild);
       
    70 	}
       
    71 
       
    72 
       
    73 void CSISVersion::Verify (const TUint32 aLanguages) const
       
    74 	{
       
    75 	CStructure <CSISFieldRoot::ESISVersion>::Verify (aLanguages);
       
    76 
       
    77 	if (iPermitAny)
       
    78 		{
       
    79 		CSISException::ThrowIf ((Major () < KIrrelevant) || (Minor () < KIrrelevant) || (Build () < KIrrelevant),
       
    80 								CSISException::EVerification,
       
    81 								"bad version");
       
    82 		}
       
    83 	else
       
    84 		{
       
    85 		CSISException::ThrowIf ((Major () < 0) || (Minor () < 0) || (Build () < 0),
       
    86 								CSISException::EVerification,
       
    87 								"bad version");
       
    88 		}
       
    89 	}
       
    90 
       
    91 void CSISVersion::AddPackageEntry(std::wostream& aStream, bool aVerbose) const
       
    92 	{
       
    93 	(void)aVerbose;
       
    94 	aStream << iMajor << L", " << iMinor << L", " << iBuild;
       
    95 	}
       
    96 
       
    97 
       
    98 
       
    99 #ifdef GENERATE_ERRORS
       
   100 void CSISVersion::CreateDefects ()
       
   101 	{
       
   102 	if (CSISVersion::IsBugToBeCreated (CSISFieldRoot::EBugInvalidValues))
       
   103 		{
       
   104 		iMajor = rand ();
       
   105 		}
       
   106 	if (CSISVersion::IsBugToBeCreated (CSISFieldRoot::EBugInvalidValues))
       
   107 		{
       
   108 		iMinor = rand ();
       
   109 		}
       
   110 	if (CSISVersion::IsBugToBeCreated (CSISFieldRoot::EBugInvalidValues))
       
   111 		{
       
   112 		iBuild = rand ();
       
   113 		}
       
   114 	}
       
   115 #endif // GENERATE_ERRORS
       
   116 
       
   117 
       
   118 
       
   119 bool operator == (const CSISVersion& aLHS, const CSISVersion& aRHS)
       
   120 	{
       
   121 	return	(aLHS.Major () == aRHS.Major ()) &&
       
   122 			(aLHS.Minor () == aRHS.Minor ()) &&
       
   123 			(aLHS.Build () == aRHS.Build ());
       
   124 	}
       
   125 
       
   126 
       
   127 bool operator < (const CSISVersion& aLHS, const CSISVersion& aRHS)
       
   128 	{
       
   129 	if (aRHS.Major () == KIrrelevant) 
       
   130 		{
       
   131 		return false;
       
   132 		}
       
   133 	if (aLHS.Major () < aRHS.Major ())
       
   134 		{
       
   135 		return true;
       
   136 		}
       
   137 	if (	(aLHS.Major () > aRHS.Major ()) ||
       
   138 			(aRHS.Minor () == KIrrelevant))
       
   139 		{
       
   140 		return false;
       
   141 		}
       
   142 
       
   143 	if (aLHS.Minor () < aRHS.Minor ())
       
   144 		{
       
   145 		return true;
       
   146 		}
       
   147 	if (	(aLHS.Minor () > aRHS.Minor ()) ||
       
   148 			(aRHS.Build () == KIrrelevant))
       
   149 		{
       
   150 		return false;
       
   151 		}
       
   152 	return aLHS.Build () < aRHS.Build ();
       
   153 	}
       
   154 
       
   155 
       
   156