Skip to content

RefactoringPlantComponentApproach

Jason Glazer edited this page Apr 4, 2016 · 4 revisions

#Approach for Refactoring Plant Components

General Notes:

  • 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

Style:

  • 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();
}

Restructure:

  1. Pass over existing diff: https://github.com/energy-plus/EnergyPlus/pull/13/files
  2. Delete namespace variables that could conflict with data structure variables
  3. Compile: stitch together without namespace variables anymore
  4. Inherit BaseClass (PlantComponent)
  5. (still a struct) Add : BaseClass (PlantComponent)
  6. Implement virtual void simulate(...) override;
  7. Look at original SimXYZ() and decide whether to override other virtual functions:
    1. For example: getDesignCapacities(), getSizingFac(), etc.
  8. Add static factory ( getInput, look for component, return pointer or fatal )
  9. Call factory from PlantManager
  10. Call compPtr->simulate() from PlantLoopEquip
  11. Change worker functions to member functions:
    1. Remove index in the function, replacing "Comp( CompNum )." with "this->"
    2. Move function declaration into struct
    3. Get rid of EP_UNUSED arguments, (except in overridden functions)
  12. Make sure GetInput doesn't look to outside:
  13. Example: ScanPlantLoopsForObject which looks at other plant loops, move into init()
  14. Example: UserDefinedComps GetInput was getting plant AND zone stuff; pull plant into its own GetInput
  15. Search the code for your GetInput function and make sure it is protected from reentry (if getInputFlag)
  16. Make sure an integration test covers this object well
Clone this wiki locally