@@ -167,134 +167,4 @@ struct NodeHasher {
167167 }
168168};
169169
170- inline e_rr_type string_to_node_type (const std::string& str) {
171- if (str == " SOURCE" || str == " source" ) return e_rr_type::SOURCE;
172- if (str == " SINK" || str == " sink" ) return e_rr_type::SINK;
173- if (str == " IPIN" || str == " ipin" ) return e_rr_type::IPIN;
174- if (str == " OPIN" || str == " opin" ) return e_rr_type::OPIN;
175- if (str == " CHANX" || str == " chanx" ) return e_rr_type::CHANX;
176- if (str == " CHANY" || str == " chany" ) return e_rr_type::CHANY;
177- throw std::invalid_argument (" Unknown node type: " + str);
178- }
179-
180- inline std::string to_string (Direction dir) {
181- return (dir == Direction::INC_DIR) ? " INC_DIR" : " DEC_DIR" ;
182- }
183-
184- inline std::string to_string (Side side) {
185- switch (side) {
186- case Side::LEFT:
187- return " Left" ;
188- case Side::RIGHT:
189- return " Right" ;
190- case Side::TOP:
191- return " Top" ;
192- case Side::BOTTOM:
193- return " Bottom" ;
194- case Side::IPIN:
195- return " IPIN" ;
196- case Side::OPIN:
197- return " OPIN" ;
198- default :
199- return " UNKNOWN" ;
200- }
201- }
202-
203- inline Side string_to_side (const std::string& str) {
204- if (str == " Left" ) return Side::LEFT;
205- if (str == " Right" ) return Side::RIGHT;
206- if (str == " Top" ) return Side::TOP;
207- if (str == " Bottom" ) return Side::BOTTOM;
208- if (str == " IPIN" ) return Side::IPIN;
209- if (str == " OPIN" ) return Side::OPIN;
210- throw std::invalid_argument (" Unknown side: " + str);
211- }
212-
213- /* *
214- * @brief Get the memory usage
215- * @return Memory usage in KB
216- */
217- inline size_t get_memory_usage () {
218- #ifdef _WIN32
219- PROCESS_MEMORY_COUNTERS pmc;
220- if (GetProcessMemoryInfo (GetCurrentProcess (), &pmc, sizeof (pmc))) {
221- return pmc.WorkingSetSize / 1024 ; // Convert bytes to KB
222- }
223- return 0 ;
224- #else
225- struct rusage usage;
226- getrusage (RUSAGE_SELF, &usage);
227- return static_cast <size_t >(usage.ru_maxrss ); // Already in KB on Linux, bytes on macOS
228- #ifdef __APPLE__
229- return static_cast <size_t >(usage.ru_maxrss / 1024 ); // Convert bytes to KB on macOS
230- #endif
231- #endif
232- }
233-
234- /* *
235- * @brief Get the peak memory usage
236- * @return Peak memory usage in KB
237- */
238- inline size_t get_peak_memory_usage () {
239- #ifdef _WIN32
240- PROCESS_MEMORY_COUNTERS pmc;
241- if (GetProcessMemoryInfo (GetCurrentProcess (), &pmc, sizeof (pmc))) {
242- return pmc.PeakWorkingSetSize / 1024 ; // Convert bytes to KB
243- }
244- return 0 ;
245- #else
246- // On Unix/Linux, we need to read /proc/self/status for peak memory
247- std::ifstream status_file (" /proc/self/status" );
248- std::string line;
249- while (std::getline (status_file, line)) {
250- if (line.substr (0 , 6 ) == " VmHWM:" ) {
251- std::istringstream iss (line);
252- std::string label, value, unit;
253- iss >> label >> value >> unit;
254- return std::stoul (value); // Already in KB
255- }
256- }
257-
258- // Fallback to getrusage if /proc/self/status is not available
259- struct rusage usage;
260- getrusage (RUSAGE_SELF, &usage);
261- #ifdef __APPLE__
262- return static_cast <size_t >(usage.ru_maxrss / 1024 ); // Convert bytes to KB on macOS
263- #else
264- return static_cast <size_t >(usage.ru_maxrss ); // Already in KB on Linux
265- #endif
266- #endif
267- }
268-
269- // Exception classes
270- class RRGeneratorException : public std ::runtime_error {
271- public:
272- explicit RRGeneratorException (const std::string& message)
273- : std::runtime_error(message) {}
274- };
275-
276- class ConfigException : public RRGeneratorException {
277- public:
278- explicit ConfigException (const std::string& message)
279- : RRGeneratorException(" Configuration error: " + message) {}
280- };
281-
282- class FileException : public RRGeneratorException {
283- public:
284- explicit FileException (const std::string& message)
285- : RRGeneratorException(" File error: " + message) {}
286- };
287-
288- class ParseException : public RRGeneratorException {
289- public:
290- explicit ParseException (const std::string& message)
291- : RRGeneratorException(" Parse error: " + message) {}
292- };
293-
294- class SwitchException : public RRGeneratorException {
295- public:
296- explicit SwitchException (const std::string& message)
297- : RRGeneratorException(" Switch error: " + message) {}
298- };
299-
300170} // namespace crrgenerator
0 commit comments