00001 #ifndef MYTHUIUTILS_H_
00002 #define MYTHUIUTILS_H_
00003
00004 #include <cstdlib>
00005
00006 #include "mythuiexp.h"
00007
00008 class QString;
00009
00010 struct MUI_PUBLIC ETPrintWarning
00011 {
00012 static bool Child(const QString &container_name, const QString &child_name);
00013 static bool Container(const QString &child_name);
00014 };
00015
00016 struct MUI_PUBLIC ETPrintError
00017 {
00018 static bool Child(const QString &container_name, const QString &child_name);
00019 static bool Container(const QString &child_name);
00020 };
00021
00022 template <typename ErrorDispatch = ETPrintWarning>
00023 struct UIUtilDisp
00024 {
00025 template <typename ContainerType, typename UIType>
00026 static bool Assign(ContainerType *container, UIType *&item,
00027 const QString &name, bool *err = NULL)
00028 {
00029 if (!container)
00030 {
00031 if (err)
00032 *err |= ErrorDispatch::Container(name);
00033 else
00034 ErrorDispatch::Container(name);
00035 return true;
00036 }
00037
00038 item = dynamic_cast<UIType *>(container->GetChild(name));
00039
00040 if (item)
00041 return false;
00042
00043 if (err)
00044 *err |= ErrorDispatch::Child(container->objectName(), name);
00045 else
00046 ErrorDispatch::Child(container->objectName(), name);
00047 return true;
00048 }
00049 };
00050
00051 typedef struct UIUtilDisp<ETPrintWarning> UIUtilW;
00052 typedef struct UIUtilDisp<ETPrintError> UIUtilE;
00053
00054 #endif