imgtools/imgcheck/src/exceptionimplementation.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
    17 *
    17 *
    18 */
    18 */
    19 
    19 
    20 
    20 
    21 /**
    21 /**
    22  @file
    22 @file
    23  @internalComponent
    23 @internalComponent
    24  @released
    24 @released
    25 */
    25 */
    26 
    26 
    27 #include "exceptionimplementation.h"
    27 #include "exceptionimplementation.h"
    28 
    28 
    29 enum MessageArraySize{MAX=42};
    29 enum MessageArraySize{MAX=42};
    33 message required by imgcheck tool.
    33 message required by imgcheck tool.
    34 
    34 
    35 @internalComponent
    35 @internalComponent
    36 @released
    36 @released
    37 */
    37 */
    38 struct Messages MessageArray[MAX]=
    38 struct Messages MessageArray[MAX]= {
    39 {
       
    40 	{UNKNOWNIMAGETYPE, "Error: Image Type Unknown: '%s'"},
    39 	{UNKNOWNIMAGETYPE, "Error: Image Type Unknown: '%s'"},
    41 	{UNKNOWNPREFIX,"Error: Option has Un-Known Prefix: '%s'"},
    40 	{UNKNOWNPREFIX,"Error: Option has Un-Known Prefix: '%s'"},
    42 	{VALUEEXPECTED,"Error: Value expected for option: '%s'"},
    41 	{VALUEEXPECTED,"Error: Value expected for option: '%s'"},
    43 	{VALUENOTEXPECTED,"Error: Value not expected for option: '%s'"},
    42 	{VALUENOTEXPECTED,"Error: Value not expected for option: '%s'"},
    44 	{UNKNOWNOPTION,"Error: Unknown option: '%s'"},
    43 	{UNKNOWNOPTION,"Error: Unknown option: '%s'"},
   103 
   102 
   104 @param aCmdFlag - has all the options received in commandline.
   103 @param aCmdFlag - has all the options received in commandline.
   105 
   104 
   106 @return - returns the instance
   105 @return - returns the instance
   107 */
   106 */
   108 ExceptionImplementation* ExceptionImplementation::Instance(unsigned int aCmdFlag)
   107 ExceptionImplementation* ExceptionImplementation::Instance(unsigned int aCmdFlag) {
   109 {
   108 	if(iInstance == KNull) {
   110 	if(iInstance == KNull)
       
   111 	{
       
   112 		iCmdFlag = aCmdFlag;
   109 		iCmdFlag = aCmdFlag;
   113 		iInstance = new ExceptionImplementation();
   110 		iInstance = new ExceptionImplementation();
   114 	}
   111 	}
   115 	return iInstance;
   112 	return iInstance;
   116 }
   113 }
   119 Static function to delete the instance.
   116 Static function to delete the instance.
   120 
   117 
   121 @internalComponent
   118 @internalComponent
   122 @released
   119 @released
   123 */
   120 */
   124 void ExceptionImplementation::DeleteInstance()
   121 void ExceptionImplementation::DeleteInstance() {
   125 {
       
   126 	DELETE(iInstance);
   122 	DELETE(iInstance);
   127 }
   123 }
   128 
   124 
   129 /**
   125 /**
   130 Constructor opens the output stream and traverses through MessageArray objects to 
   126 Constructor opens the output stream and traverses through MessageArray objects to 
   132 
   128 
   133 @internalComponent
   129 @internalComponent
   134 @released
   130 @released
   135 */
   131 */
   136 ExceptionImplementation::ExceptionImplementation()
   132 ExceptionImplementation::ExceptionImplementation()
   137 :iMsgIndex(0)
   133 :iMsgIndex(0) {
   138 {
   134 	iLogStream.open(gLogFileName.c_str(),ios_base::out);
   139 	iLogStream.open(gLogFileName.c_str(),Ios::out);
       
   140 	int i;
   135 	int i;
   141 	for(i = 0; i < MAX; i++)
   136 	for(i = 0; i < MAX; i++) {
   142 	{
   137 		iMessage.insert(make_pair(MessageArray[i].iIndex,MessageArray[i].iMessage));
   143 		iMessage.insert(std::make_pair(MessageArray[i].iIndex,MessageArray[i].iMessage));
       
   144 	}
   138 	}
   145 }
   139 }
   146 
   140 
   147 /**
   141 /**
   148 Destructor closes the output stream opened during construction.
   142 Destructor closes the output stream opened during construction.
   149 
   143 
   150 @internalComponent
   144 @internalComponent
   151 @released
   145 @released
   152 */
   146 */
   153 ExceptionImplementation::~ExceptionImplementation()
   147 ExceptionImplementation::~ExceptionImplementation() {
   154 {
       
   155 	iLogStream.close();
   148 	iLogStream.close();
   156 }
   149 }
   157 
   150 
   158 /**
   151 /**
   159 Function returns the message equivalent to the recived enum value.
   152 Function returns the message equivalent to the recived enum value.
   161 @internalComponent
   154 @internalComponent
   162 @released
   155 @released
   163 
   156 
   164 @param aMsgIndex - enum value
   157 @param aMsgIndex - enum value
   165 */
   158 */
   166 String& ExceptionImplementation::Message(const int aMsgIndex)
   159 string& ExceptionImplementation::Message(const int aMsgIndex) {
   167 {
       
   168 	iMsgIndex = aMsgIndex;
   160 	iMsgIndex = aMsgIndex;
   169 	return iMessage[aMsgIndex];
   161 	return iMessage[aMsgIndex];
   170 }
   162 }
   171 
   163 
   172 /**
   164 /**
   179 @internalComponent
   171 @internalComponent
   180 @released
   172 @released
   181 
   173 
   182 @param aMsgIndex - enum value
   174 @param aMsgIndex - enum value
   183 */
   175 */
   184 void ExceptionImplementation::Log(const String aMsg)
   176 void ExceptionImplementation::Log(const string aMsg) {
   185 {
       
   186 	iLogStream <<  aMsg.c_str() << "\n";
   177 	iLogStream <<  aMsg.c_str() << "\n";
   187     
   178 
   188 	if(iCmdFlag & KVerbose)
   179 	if(iCmdFlag & KVerbose) {
   189 	{
       
   190 		cout << aMsg.c_str() << endl;
   180 		cout << aMsg.c_str() << endl;
   191 	}
   181 	}
   192 }
   182 }
   193 
   183 
   194 /**
   184 /**
   200 @internalComponent
   190 @internalComponent
   201 @released
   191 @released
   202 
   192 
   203 @param aMsgIndex - enum value
   193 @param aMsgIndex - enum value
   204 */
   194 */
   205 void ExceptionImplementation::Report(const String aMsg)
   195 void ExceptionImplementation::Report(const string aMsg) {
   206 {
       
   207 	iLogStream <<  aMsg.c_str() << "\n";
   196 	iLogStream <<  aMsg.c_str() << "\n";
   208 	if(aMsg.find("Success") != String::npos)
   197 	if(aMsg.find("Success") != string::npos) {
   209 	{
       
   210 		cout << aMsg.c_str() << endl;
   198 		cout << aMsg.c_str() << endl;
   211 	}
   199 	}
   212 	else
   200 	else {
   213 	{
       
   214 		cerr << aMsg.c_str() << endl;
   201 		cerr << aMsg.c_str() << endl;
   215 	}
   202 	}
   216 }
   203 }