|
From: <bl...@us...> - 2003-03-16 14:39:19
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv22508/include/rfta/refactoring
Modified Files:
CodeModelElement.h CodeModelStatements.h
Log Message:
* refactored to use ChangeTracker in statements
Index: CodeModelElement.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelElement.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** CodeModelElement.h 16 Mar 2003 13:51:06 -0000 1.8
--- CodeModelElement.h 16 Mar 2003 14:39:13 -0000 1.9
***************
*** 6,12 ****
#define RFTA_CODEMODELELEMENT_H
! #include <rfta/refactoring/Config.h>
#include <rfta/parser/SourceRange.h>
#include <rfta/parser/ASTNodeForward.h>
namespace Refactoring { namespace CodeModel
--- 6,13 ----
#define RFTA_CODEMODELELEMENT_H
! #include <rfta/refactoring/CodeModelForward.h>
#include <rfta/parser/SourceRange.h>
#include <rfta/parser/ASTNodeForward.h>
+ #include <stdexcept>
namespace Refactoring { namespace CodeModel
***************
*** 96,103 ****
--- 97,170 ----
+ struct NoConstraintPolicy
+ {
+ template<typename Type>
+ static void checkConstraint( const Type & )
+ {
+ }
+ };
+
+ struct NotNullConstraintPolicy
+ {
+ template<typename Type>
+ static void checkConstraint( const Type &pointer )
+ {
+ if ( !pointer )
+ throw std::invalid_argument( "ChangeTracker: parameter can not be null." );
+ }
+ };
+
+
+ // Change.type_ can only either replaced or unmodified.
+ template<typename TrackedType
+ ,typename ConstraintPolicy = NotNullConstraintPolicy>
class ChangeTracker
{
+ public:
+ ChangeTracker( const TrackedType &element )
+ : element_( element )
+ {
+ ConstraintPolicy::checkConstraint( element );
+ }
+
+ void setElementIsFromSource()
+ {
+ change_.type_ = Change::unmodified;
+ change_.oldRange_ = hasElement() ? element_->getSourceRange()
+ : SourceRange();
+ }
+
+ void setElement( const TrackedType &newElement )
+ {
+ ConstraintPolicy::checkConstraint( newElement );
+
+ change_.type_ = Change::replaced;
+ element_ = newElement;
+ }
+
+ bool hasElement() const
+ {
+ return element_;
+ }
+
+ TrackedType getElement() const
+ {
+ return element_;
+ }
+
+ Change getChange() const
+ {
+ return change_;
+ }
+
+ private:
+ Change change_;
+ TrackedType element_;
};
+
+
+ typedef ChangeTracker<StatementPtr> StatementChangeTracker;
+ typedef ChangeTracker<ExpressionPtr> ExpressionChangeTracker;
Index: CodeModelStatements.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelStatements.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** CodeModelStatements.h 16 Mar 2003 13:51:06 -0000 1.9
--- CodeModelStatements.h 16 Mar 2003 14:39:13 -0000 1.10
***************
*** 80,83 ****
--- 80,84 ----
ExpressionPtr getCondition() const;
+
void setCondition( const ExpressionPtr &condition );
***************
*** 86,90 ****
private:
! ExpressionPtr condition_;
};
--- 87,91 ----
private:
! ExpressionChangeTracker conditionTracker_;
};
***************
*** 136,140 ****
private:
! StatementPtr iteratedStatement_;
};
--- 137,141 ----
private:
! StatementChangeTracker iteratedStatementTracker_;
};
***************
*** 198,202 ****
private:
! CompoundStatementPtr statements_;
};
--- 199,203 ----
private:
! ChangeTracker<CompoundStatementPtr> statementsTracker_;
};
***************
*** 220,227 ****
const std::string getLabelName() const;
void setLabelName( const std::string &labelName );
private:
! std::string labelName_;
};
--- 221,229 ----
const std::string getLabelName() const;
+
void setLabelName( const std::string &labelName );
private:
! ChangeTracker<std::string,NoConstraintPolicy> labelNameTracker_;
};
***************
*** 263,266 ****
--- 265,269 ----
ExpressionPtr getConditionValue() const;
+
void setConditionValue( const ExpressionPtr &conditionValue );
***************
*** 269,273 ****
private:
! ExpressionPtr conditionValue_;
};
--- 272,276 ----
private:
! ExpressionChangeTracker conditionValueTracker_;
};
***************
*** 333,337 ****
private:
! ExpressionPtr expression_;
};
--- 336,340 ----
private:
! ExpressionChangeTracker expressionTracker_;
};
|