#ifndef LIBUTILS_H #define LIBUTILS_H /////////////////////////////////////////////////////////////////// // LibUtils.h - utility functions and classes for all libraries // // ver 1.0 // // ------------------------------------------------------------- // // copyright © Jim Fawcett, 2012 // // All rights granted provided that this notice is retained // // ------------------------------------------------------------- // // Jim Fawcett, CST 4-187, Syracuse University, 315 443 3948 // // Summer Projects, 2012 // // Win7, Visual Studio 2010 // /////////////////////////////////////////////////////////////////// /* * Package Operations: * =================== * This package provides classes: * - SearchableStack * And provides the functions: * - fromString * - toString */ #include #include namespace LibUtils { template inline T fromString(const std::string& s) { std::istringstream temp(s); T t; temp >> t; return t; } template inline std::string toString(const T& t) { std::ostringstream temp; temp << t; return temp.str(); } template class SearchableStack { public: void push(T& t) { stack.push_back(t); } T pop() { T t = stack.back(); stack.pop_back(); return t; } T& top() { return stack.back(); } size_t size() { return stack.size(); } bool contains(T& t) { for(size_t i=0; i stack; }; } #endif