00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/generic/om/LogicElement.hpp"
00017 #include "torc/generic/om/LogicValue.hpp"
00018
00019 namespace torc {
00020
00021 namespace generic {
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 LogicElementSharedPtr
00034 LogicElement::Factory::newLogicElementPtr( const LogicElement::Type & inType,
00035 const LogicValueSharedPtr & inLogicValue,
00036 const LogicElementSharedPtr & inParentLogicElement ) throw(Error) {
00037 try
00038 {
00039 LogicElementSharedPtr newLogicElement;
00040 create( newLogicElement );
00041 newLogicElement->setType( inType );
00042 if( inLogicValue )
00043 {
00044 newLogicElement->setName( inLogicValue->getName() );
00045 }
00046 if( inParentLogicElement )
00047 {
00048 inParentLogicElement->addChildLogicElement( newLogicElement );
00049 }
00050 return newLogicElement;
00051 }
00052 catch( Error &e )
00053 {
00054 e.setCurrentLocation(
00055 __FUNCTION__, __FILE__, __LINE__ );
00056 throw;
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065 void
00066 LogicElement::setType( const Type & inSource ) throw() {
00067 mType = inSource;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077 void
00078 LogicElement::setChildren(
00079 const std::vector< LogicElementSharedPtr > & inSource ) throw() {
00080 std::vector< LogicElementSharedPtr >::const_iterator entry = inSource.begin();
00081 std::vector< LogicElementSharedPtr >::const_iterator end = inSource.end();
00082 for(; entry != end; ++entry )
00083 {
00084 try
00085 {
00086 addChildLogicElement( *entry );
00087 }
00088 catch( Error &e )
00089 {
00090 e.setCurrentLocation(
00091 __FUNCTION__, __FILE__, __LINE__ );
00092 throw;
00093 }
00094 }
00095 }
00096
00097
00098
00099
00100
00101
00102 bool
00103 LogicElement::addChildLogicElement(
00104 const LogicElementSharedPtr & inChildLogicElement) throw() {
00105 if( !inChildLogicElement )
00106 {
00107 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00108 __FUNCTION__, __FILE__, __LINE__ );
00109 e.saveContextData("Pointer to the logic element object does not exist", inChildLogicElement);
00110 throw e;
00111 }
00112 else
00113 {
00114 mChildren.push_back( inChildLogicElement );
00115 return true;
00116 }
00117 }
00118
00119 void
00120 LogicElement::accept(BaseVisitor & visitor) throw(Error) {
00121 try
00122 {
00123 runVisitor( *this, visitor );
00124 }
00125 catch( Error &e )
00126 {
00127 e.setCurrentLocation(
00128 __FUNCTION__, __FILE__, __LINE__ );
00129 throw;
00130 }
00131 }
00132
00133
00134
00135
00136
00137
00138 void
00139 LogicElement::setRelationType(const RelationType & inSource) throw() {
00140 mRelationType = inSource;
00141 }
00142
00143
00144
00145
00146
00147 size_t
00148 LogicElement::getSize() const throw() {
00149 size_t size = 0;
00150 size_t pSize = 0;
00151 size_t cSize = 0;
00152 LogicElement::RelationType rType = getRelationType();
00153
00154 std::vector< LogicElementSharedPtr > outLogicElements;
00155 getChildren( outLogicElements );
00156
00157 std::vector< LogicElementSharedPtr >::iterator logicElemIt
00158 = outLogicElements.begin();
00159 if( LogicElement::eTypeSingle == getType()
00160 || LogicElement::eTypeIgnored == getType() )
00161 {
00162 return 1;
00163 }
00164
00165 if( LogicElement::eTypeOneOf == getType() )
00166 {
00167 if( !outLogicElements.empty() )
00168 {
00169 size += (*logicElemIt)->getSize();
00170 }
00171 else
00172 {
00173 size = 0;
00174 }
00175 return size;
00176 }
00177
00178 if( LogicElement::eTypeWaveForm == getType() )
00179 {
00180 if( !outLogicElements.empty() )
00181 {
00182 size += (*logicElemIt)->getSize();
00183 }
00184 else
00185 {
00186 size = 0;
00187 }
00188 return size;
00189 }
00190
00191 if( LogicElement::eRelationTypeParent == rType )
00192 {
00193 if( !outLogicElements.empty() )
00194 {
00195 pSize += (*logicElemIt)->getSize();
00196 }
00197 else
00198 {
00199 pSize = 0;
00200 }
00201 }
00202 else
00203 {
00204 if( !outLogicElements.empty() )
00205 {
00206 for( ; logicElemIt != outLogicElements.end() ; logicElemIt ++ )
00207 {
00208 cSize += (*logicElemIt)->getSize();
00209 }
00210 }
00211 }
00212 size = pSize + cSize;
00213 return size;
00214 }
00215
00216 LogicElement::LogicElement()
00217 : LogicValue(),
00218 mType(),
00219 mRelationType(),
00220 mChildren() {
00221 }
00222
00223 LogicElement::~LogicElement() throw() {
00224 }
00225
00226
00227 }
00228
00229 }