When I visited the new features of "cocos2dx 3.0rc0", I suddenly found a strange figure:Value. Why is this product so familiar? After a while, I suddenly realized. Does value mean "value ?! I can't help but feel that my English skills have grown.
When CCArray is used at first, the int or float type variables cannot be inserted in, because the int type identity is "too low" and is not a member of the Object family. I decided to move closer to the aristocratic members CCInteger and CCFloat. Later, in the version later than beta, CCArray and CCDictionary fell victim to a sharp decrease in the family position of CCInteger and CCFloat in objects. Although the Object as the head of the family does not want to see its children and grandchildren fall down, it cannot change the status quo because it is too old. So, when the 999-year-old Object had the last point of its own... energy..., he quickly marriedRefAfter working overtime, the young girl named "Value" was born. Time is like water, in a twinkling of an eye, the Object has been behind the scenes, with peace of mind for the elderly; Ref replaces the status of the Object's home master in the world; CCInter and other out of favor are assigned to the frontier, after a while, it will disappear to people's sight forever. As a replacement for CCInteger and so on, Value began to take up its posts, distributing its light and heat, and finallyIt will go through the Chinese continent of the gods, lead the peasants to the armed uprising, and successfully become a brother with Qi tianda, and successfully break through the void and the rivers and lakes will be short of breath after it overcomes all the obstacles of the twelve kinggirls, the length of your child .... of course, this is all about the background.(Put away the angry watermelon knife in your hand)
Next we will go to CCValue. h to see what the Value is. Let's take a look at some typical APIs.
Explicit Value (int v); xplicit Value (float v); // assign a Value Deputy title directly, such as Value (10.0); Value & operator = (int v ); value & operator = (float v); // create a variable and assign a Value, for example, Value val (10.0); int asInt () const; // convert the Value into an integer float asFloat () const; // floating point type // determine whether the Value is empty inline bool isNull () const {return _ Type = type :: NONE;} std: string getDescription (); // get the description of a Value. The return Type is string-type inline Type getType () const {return _ type ;}; // obtain the Type of Value. // The total types of Value include enum class Type {NONE, BYTE, INTEGER, FLOAT, DOUBLE, BOOLEAN, STRING, VECTOR, MAP, INT_KEY_MAP };
Some simple applications are listed below:
// ---------------------------------------------------- Value val; // call the default constructor and initialize it as null if (val. isNull () // determines whether it is null {log ("val is null");} else {std: string str = val. getDescription (); log ("The description of val0: % s", str. c_str ();} Value val1 (65); // Initialization is an integer // Value val1 (3.4f ); // initialize to floating point log ("The description of the integer value val1: % s", val1.getDescription (). c_str (); // output the description of val1 (that is, its content) log ("val1.asByte () = % c", val1.asByte ()); // convert int type to byte type (A) // -------------------------------------------------------- std: string strV = "10"; Value val2 (strV ); // initialize to string log ("The description of the string value val2: % s", val2.getDescription (). c_str (); int val_int = val2.asInt (); // convert string type to int type (that is, so useful) log ("turn string to int, the val_int value: % d ", val_int); // ----------- the following lists some deeper applications ---------------------------- auto sp0 = Sprite: create (); Vector
* VecV = new Vector
(); VecV-> pushBack (sp0); Value val3 (vecV); // initialize with Vectorlog ("The description of the Vector value: % s", val3.getDescription (). c_str (); delete vecV; // ------------------------------------------------------ Map
* MapV = new Map
(); MapV-> insert (strV, sp0); Value val4 (mapV); // initialize with Maplog ("The description of the Map value: % s ", val4.getDescription (). c_str (); delete mapV; // -------------------------------------------------- Value val6 (& val4); // initialize with Maplog ("The description of the Value-type value: % s ", val6.getDescription (). c_str (); // invalid val2 = val1; // assigning between 2 Value-typelog ("operator-> The description of val2: % s", val2.getDescription (). c_str (); val2 = 4; // assigning directlylog ("operator-> The description of val4: % s", val2.getDescription (). c_str ());
Shows the output:
Well, that's it.
Reference link: https://github.com/cocos2d/cocos-docs/blob/master/manual/framework/native/data-structure/v3/value/en.md
Respect Original, forward please indicate Source: http://blog.csdn.net/start530/article/details/21651751