#ifndef REQDB_H #define REQDB_H /////////////////////////////////////////////////////////////// // reqDB.h - Prototype for Project #1 // // ver 1.0 Requirements Database // // // // Language: Visual C++, ver 6.0 // // Platform: Del XPS1000, Windows 2000 Professional // // Application: CSE691, Pr1 demo, Fall 2000 // // Author: Jim Fawcett, CST 2-187, Syracuse Univ. // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////// /* Module Operations: ================== This module provides four classes: - itemNumber represents numbers of the form A16 - item represents database items with fields: - itemNumber - title - text - allocations - priority - date - parse provides low-level operations for converting items between a tagged xml style representation used in files and an in-memory structure - ReqDB reads from a file, holds in memory, and writes back out to a file a vector of items. Public Interface: ================= Too Be Specified (TBS) */ /////////////////////////////////////////////////////////////// // build process // /////////////////////////////////////////////////////////////// // required files: // // reqDB.h, reqDB.cpp // // // // compiler command: // // cl /GX /DTEST_REQDB reqDB.cpp // /////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.0 : 18 Sep 2000 - first release */ // #pragma warning(disable : 4786) #include #include #include #include ///////////////////////////////////////////////////////////////////////////// // class itemNumber - represents a database item number, e.g., B15 // class itemNumber { public: itemNumber(); itemNumber(const std::string &s); // convert to and from strings void get(const std::string &s); std::string put(); // test for validity, e.g., type is A, B, D, or P // and number is non-negative bool isValid(); // comparisons bool operator<(const itemNumber &item) const; bool operator==(const itemNumber &item) const; // access to type and number char type() const; int number() const; private: char _type; int _number; int makeInt(const char *s); }; std::ostream& operator<<(std::ostream &out, const itemNumber &itnum) { std::cout << itnum.type() << itnum.number(); return out; } // ///////////////////////////////////////////////////////////////////////////// // class parse - handles conversion from xml string to database item // class parse { public: // accept an xml string rep parse(const std::string &rep); // extract data and attributes from the xml rep bool getData(const std::string &tag, std::string &data); bool getFirstAttr(const std::string &tag, std::string &attr); private: int getTag(const std::string &tag); void validate(int position); std::string rep; }; ///////////////////////////////////////////////////////////////////////////// // These functions are related to parse class, but don't need parse's data. // They are provided to help build a tagged data item // //----< construct a begin tag >-------------------------------- std::string begTag (const std::string &tag); //----< construct an end tag >--------------------------------- std::string endTag (const std::string &tag); //----< construct a closed tag >------------------------------- std::string closedTag(const std::string &tag); //----< add an attribute to a begin tag >---------------------- std::string addAttr(const std::string &rep, const std::string &attr); //----< add data to a string with at least a begin tag >------- std::string addData(const std::string &rep, const std::string &data); //----< make a tagged item, e.g., begin payload, end tags >---- std::string makeTaggedItem(const std::string &tag, const std::string &data); //----< throw an exception if positon is beyond string >------- inline void validate(int position, const std::string test) { if(position >= test.size()) throw "search failure in string"; } // ///////////////////////////////////////////////////////////////////////////// // class item - represents a requirements database item // class item { public: enum Priority { low, normal, high }; // convert between file and in-memory representations bool getItem (const std::string &repStr); std::string putItem(bool format=false) const; // return item as a formatted string for display std::string showItem() const; // extract fields from item itemNumber& number(); itemNumber number() const; std::string& title(); std::string title() const; std::string& text(); std::string text() const; std::set& allocations(); std::set allocations() const; Priority& priority(); Priority priority() const; // convert non-string fields to strings std::string convert(const itemNumber &itNum) const; std::string convert(const std::set &allocs) const; std::string convert(const Priority &prior) const; // compare items by number, title, and data (not implemented yet) bool lessItem (const itemNumber &item); bool lessTitle(const itemNumber &item); bool lessDate (const itemNumber &item); bool operator==(const itemNumber &item); private: itemNumber itemNum; std::string _title; std::string _text; std::set alloc; Priority pri; // extract item fields from an xml string representation bool getNumber (const std::string &repStr); bool getTitle (const std::string &repStr); bool getText (const std::string &repStr); bool getAlloc (const std::string &repStr); bool getPriority(const std::string &repStr); bool getDate (const std::string &repStr); }; // ///////////////////////////////////////////////////////////////////////////// // class ReqDB - this is, finally, the database itself // class ReqDB { public: // read db from file, write db back to same file ReqDB(const std::string &dbName=""); ~ReqDB(); // add new item to database or delete current item void addItem(const item &itm); void delItem(); // display an item or all items void showItem(); void show(); // move forward and backward through list of db items bool next(); bool prev(); // reset current location to first item void reset(); // sort db by title, number, or priority enum sortType { title, number, data, priority }; void sort(const sortType &st); // how many items in db? int size(); private: std::vector array; int currentItem; std::string name; }; inline int ReqDB::size() { return array.size(); } inline void ReqDB::addItem(const item &itm) { array.push_back(itm); } inline void ReqDB::delItem() { array.erase(array.begin() + currentItem); } #endif