Generic hardware access library
/home/cschwick/hal/generic/src/common/UnmaskedReadFactory.cc
Go to the documentation of this file.
00001 #include "hal/UnmaskedReadFactory.hh"
00002 
00003 HAL::SequencerCommand* 
00004 HAL::UnmaskedReadFactory::create( std::list<std::string>& arguments, 
00005                                   const HAL::AddressTableInterface& addressTable,
00006                                   HAL::CommandSequence& sequence ) 
00007   throw (HAL::SequencerSyntaxError, HAL::NoSuchItemException) {
00008   
00009   if ( arguments.size() < 2 || arguments.size() > 3 ) {
00010     throw ( HAL::SequencerSyntaxError("unmaskedRead command must have two or three arguments."));
00011   }
00012   std::string item = arguments.front();
00013   arguments.pop_front();
00014   // we check immediately if the item exists. So the program gets an
00015   // exception immediately and not only when the script is run
00016   if ( ! addressTable.exists( item ) ) {
00017     std::string text = "Item \"" + item +
00018       "\" does not exist in HAL::AddressTable" +
00019       "\n    (HAL::UnmaskedReadFactory::create)";
00020     throw (HAL::NoSuchItemException( text, __FILE__, __LINE__, __FUNCTION__ ));
00021   }
00022   
00023   HAL::UnmaskedReadCommand* commandPtr = new HAL::UnmaskedReadCommand (item, sequence); 
00024 
00025   std::string resultStr = arguments.front();
00026   arguments.pop_front();
00027   
00028   if (resultStr[0] != '$') {
00029     throw ( HAL::SequencerSyntaxError("unmaskedRead command must have variable as second argument"));
00030   } else {
00031     commandPtr->setResultPointer( sequence.getVariablePointer( resultStr ));
00032   }
00033 
00034   if ( arguments.size() >= 1 ) {
00035     std::string offsetStr = arguments.front();
00036     arguments.pop_front();
00037     if (offsetStr[0] != '$') {
00038       commandPtr->setOffset( stringToNumber( offsetStr ));
00039     } else {
00040       commandPtr->setOffsetPointer( sequence.getVariablePointer( offsetStr ));
00041     }
00042   }  
00043   return commandPtr;
00044 }