-
Notifications
You must be signed in to change notification settings - Fork 392
RefactoringPlantComponentApproach
Jason Glazer edited this page Apr 4, 2016
·
4 revisions
#Approach for Refactoring Plant Components
- Clean out worthless comments throughout
- Clear_state: make sure it's there:
- (namespace variables, static class variables, arrays.deallocate(), vectors.clear(), add to EnergyPlusFixture)
- Don't unnecessarily put all variable declarations at the top of the function.
- Example: put
int i = 0; ...
INSIDE the for() loop, not at the top of the function
- Include virtual destructors, move constructors
- NameSpacesArePascalCase and ClassNamesArePascalCase and variablesAreCamelCase and functionsAreCamelCase
- Use tabs
- Use range-based for loops where possible to avoid index dependence ( for (auto & thing : things) )
- For small, local-ish variables like int, Real64, use the = initialization: int i = 1;
- Convert integer types into enums. These are the integer constants historically used to avoid string compares when checking types or key choices. Use scoped enums (a C++11 feature) when possible.
- Rename member variables from X to m_X to avoid variable shadowing.
- Eliminate "using" statements and instead use explicit scoping to avoid variable shadowing.
example of preferred indentation
class ClassName : public BaseClassName {
public:
void someFunction();
private:
void init();
}
- Pass over existing diff: https://github.com/energy-plus/EnergyPlus/pull/13/files
- Delete namespace variables that could conflict with data structure variables
- Compile: stitch together without namespace variables anymore
- Inherit BaseClass (PlantComponent)
- (still a struct) Add : BaseClass (PlantComponent)
- Implement virtual void simulate(...) override;
- Look at original SimXYZ() and decide whether to override other virtual functions:
- For example: getDesignCapacities(), getSizingFac(), etc.
- Add static factory ( getInput, look for component, return pointer or fatal )
- Call factory from PlantManager
- Call compPtr->simulate() from PlantLoopEquip
- Change worker functions to member functions:
- Remove index in the function, replacing "Comp( CompNum )." with "this->"
- Move function declaration into struct
- Get rid of EP_UNUSED arguments, (except in overridden functions)
- Make sure GetInput doesn't look to outside:
- Example: ScanPlantLoopsForObject which looks at other plant loops, move into init()
- Example: UserDefinedComps GetInput was getting plant AND zone stuff; pull plant into its own GetInput
- Search the code for your GetInput function and make sure it is protected from reentry (if getInputFlag)
- Make sure an integration test covers this object well