MyGUI  3.2.1
MyGUI_ResizingPolicy.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #ifndef __MYGUI_RESIZING_POLICY_H__
00008 #define __MYGUI_RESIZING_POLICY_H__
00009 
00010 #include "MyGUI_Prerequest.h"
00011 
00012 namespace MyGUI
00013 {
00014 
00015     struct MYGUI_EXPORT ResizingPolicy
00016     {
00017         enum Enum
00018         {
00019             Auto,
00020             Fixed,
00021             Fill,
00022             MAX
00023         };
00024 
00025         ResizingPolicy(Enum _value = MAX) :
00026             mValue(_value)
00027         {
00028         }
00029 
00030         static ResizingPolicy parse(const std::string& _value)
00031         {
00032             ResizingPolicy type;
00033             int value = 0;
00034             while (true)
00035             {
00036                 const char* name = type.getValueName(value);
00037                 if (strcmp(name, "") == 0 || name == _value)
00038                     break;
00039                 value++;
00040             }
00041             type.mValue = Enum(value);
00042             return type;
00043         }
00044 
00045         friend bool operator == (ResizingPolicy const& a, ResizingPolicy const& b)
00046         {
00047             return a.mValue == b.mValue;
00048         }
00049 
00050         friend bool operator != (ResizingPolicy const& a, ResizingPolicy const& b)
00051         {
00052             return a.mValue != b.mValue;
00053         }
00054 
00055         friend std::ostream& operator << (std::ostream& _stream, const ResizingPolicy&  _value)
00056         {
00057             _stream << _value.getValueName(_value.mValue);
00058             return _stream;
00059         }
00060 
00061         friend std::istream& operator >> (std::istream& _stream, ResizingPolicy&  _value)
00062         {
00063             std::string value;
00064             _stream >> value;
00065             _value = parse(value);
00066             return _stream;
00067         }
00068 
00069         std::string print() const
00070         {
00071             return getValueName(mValue);
00072         }
00073 
00074         int getValue() const
00075         {
00076             return mValue;
00077         }
00078 
00079     private:
00080         const char* getValueName(int _index) const
00081         {
00082             static const char* values[MAX + 1] = { "Auto", "Fixed", "Fill", "" };
00083             return values[(_index < MAX && _index >= 0) ? _index : MAX];
00084         }
00085 
00086     private:
00087         Enum mValue;
00088     };
00089 
00090 } // namespace MyGUI
00091 
00092 #endif // __MYGUI_RESIZING_POLICY_H__