Monday, 15 July 2013

Removing STL lib in c++ , how to replace a map and a vector in standards C++ -



Removing STL lib in c++ , how to replace a map and a vector in standards C++ -

i need remove stl api, must introduce collection interfaces instead of stl containers.

my question what's way replace map , vector in standards of c/c++ .

for exemple here piece of code in api:

void initialize(const std::map<int, std::string>& props, logger& logger = nulllogger::getinstance()); map<string, diagnostic> partsdiag; const std::vector<book> books; const std::string& runid_p, const std::vector<book>& books_p, runtype runtype_p,

what equivalent in these cases in c/c++?

the substitution must done in api, how manage allow stl in rest of code?

thank you

typically avoid exposing info members anyway (like partsdiag). instead provide fellow member function diagnostic getdiagforpart(string); internally accesses same old map, private. general thought substitute info access functions provide info client bit bit instead of finish collection.

the client like

void printdiags() { string parts[] = { "valve", "radio", "brake" }; auto partsdiag = api::partsdiag(); // map for( string &part: parts ) print(partsdiag[part]); }

if introduce function diagnostic getpartdiag(string) instead, code alter to:

void printdiags() { string parts[] = { "valve", "radio", "brake" }; for( string &part: parts ) print(api::getpartdiag(part)); }

the implementation of getpartdiag() of course of study still accesses map, map private implementation detail.

if need expose data, can write wrapper classes. decoupling it's best hide implementation details (like stl members) , expose abstract classes. if know clients doing can maintain interfaces minmally custom tailored needs. clients create instances of such classes through mill methods (which have provide).

c++ vector map stl

No comments:

Post a Comment