[Huawei Machine Test Exercises]57. Object Manager

Source: Internet
Author: User

Topic

Code

/* ---------------------------------------* Date: 2015-07-05* sjf0115* Title: Object Manager * Source: Huawei Machine Test Exercises----------------------- ------------------*/#include <iostream>#include "ObjMgt.h"#include <vector>using namespace STD;structobject{unsigned intKey1;unsigned intKey2;unsigned intKey3; Object (unsigned intAunsigned intBunsigned intc) {key1 = A;        Key2 = b;    Key3 = C; } Object () {}}; vector<Object>Container/ *------------------------------------------------------------------------------function: Add a single object input: Key1 external keyword KEY1 Key2 external keyword key2key3 external keyword KEY3 output: no return:-1: Failed (object already exists or other exception) 0: Successful---------------------------------------------- ---------------------------------*/intAddObject (unsigned intKey1,unsigned intKey2,unsigned intKey3) {intIsexits = Isobjectexist (Key1,key2,key3);//object already exists    if(isexits) {return-1; }//ifObject O (Key1,key2,key3); Container.push_back (o);return 0;}/*-------------------------------------------------------------------------------function: Delete one or more object inputs: Key1 external keywords       KEY1 key2 external keyword KEY2 key3 external keyword KEY3 output: no return: No Description: Use case to ensure that the parameter value is a valid value and a wildcard character 0xFFFFFFFF, the wildcard represents any value in the 0~65535 range;           Example: key1=1,key2=2,key3= 0xFFFFFFFF, which means deleting all objects of key1=1,key2=2; The Key1,key2,key3 value is all 0xFFFFFFFF, which means that all objects are deleted. -------------------------------------------------------------------------------*/voidDeleteObject (unsigned intKey1,unsigned intKey2,unsigned intKey3) {Object o; vector<Object>:: Iterator ite = Container.begin (); while(Ite! = Container.end ()) {o = *ite;if(O.key1 = = Key1 | | key1 = =0xFFFFFFFF) && (O.key2 = = Key2 | | key2 = =0xFFFFFFFF) && (O.key3 = = Key3 | | key3 = =0xFFFFFFFF) {ite = Container.erase (ITE); }//if        Else{++ite; }//else}//while    return;}/*-----------------------------------------------------------------------------------function: Query for the existence of a single object input: Key1 external keyword KEY1 key2 external keyword KEY2 key3 external keyword KEY3 output: no return: 0: Nonexistent 1: Presence----------------------------------------- ------------------------------------------*/intIsobjectexist (unsigned intKey1,unsigned intKey2,unsigned intKey3) {intSize = Container.size (); Object o; for(inti =0; i < size;++i) {o = Container[i];if(O.key1 = = Key1 && O.key2 = = Key2 && O.key3 = Key3) {return 1; }//if}//for    return 0;}/ *----------------------------------------------------------------------------------Description Empty all objects prototype void clear (), Input Param no output Param no return Value no------------------------------------ -----------------------------------------------*/voidClear (void) {container.clear ();return;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[Huawei Machine Test Exercises]57. Object Manager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.