i have these property class:
/*properties
- how use create 1 property with macro:
PROPERTY(TypeName,PropertyName,getfunction, setfunction)
- never forget to do 1 Copy Constructor inside of class's, that uses the property,
for avoid copy the 'this' value\adress and use a diferent memory adress
*/
template <typename T>
class property
{
private:
T PropertyValue;
std::function<T(void)> getf;
std::function<void(T)> setf;
public:
property(const T value)
{
getf=nullptr;
setf=nullptr;
PropertyValue=value;
};
property(const property &value) : PropertyValue(value.PropertyValue) , getf(value.getf)
{
}
property(std::function<T(void)> GetFunction=nullptr,std::function<void(T)> SetFunction=nullptr)
{
setf=SetFunction;
getf=GetFunction;
}
property& operator=(const T &value)
{
PropertyValue=value;
if (setf!=nullptr)
setf(value);
return *this;
}
property& operator=(const property &value)
{
PropertyValue = value.PropertyValue;
if (setf!=nullptr)
setf(PropertyValue);
return *this;
}
operator T()
{
if (getf!=nullptr)
return getf();
else
return PropertyValue;
}
friend ostream& operator<<(ostream& os, property& dt)
{
if(dt.getf==nullptr && dt.setf==nullptr)
os << dt.PropertyValue;
else if (dt.getf!=nullptr)
os << dt.getf();
return os;
}
friend istream& operator>>(istream &input, property &dt)
{
input >> dt.PropertyValue;
if (dt.setf!=nullptr)
dt.setf(dt.PropertyValue);
return input;
}
friend istream &getline(istream &in, property &dt)
{
getline(in, dt.PropertyValue);
if (dt.setf!=nullptr)
dt.setf(dt.PropertyValue);
return in;
}
};
/*template<typename T, typename Fnc1_t, typename Fnc2_t, typename classthis>
property<T> GetProperty(Fnc1_t Getter, Fnc2_t Setter, classthis clsthis)
{
return property<T>(std::bind(Getter, clsthis), std::bind(Setter, clsthis, std::placeholders::_1));
}
#define PROPERTY(TypeName,PropertyName,getfunction, setfunction) \
property<TypeName> PropertyName{std::bind(&getfunction, *this),std::bind(&setfunction, *this, std::placeholders::_1)}*/
#define Get(x) [this]()->x
#define Set(...) [this](__VA_ARGS__)->void
now i'm add some members on a new class:
class form
{
public:
property <boolean> TabStop
{
Get(boolean)
{
return blnTabStop;
},
Set(boolean tabstop)
{
if (blnTabStop != tabstop)
{
blnTabStop = tabstop;
long s;
if (tabstop == false)
{
s = GetWindowLongPtr(hwnd, GWL_STYLE);
s = s & ~(WS_TABSTOP);
}
else
{
s = GetWindowLongPtr(hwnd, GWL_STYLE);
s = s | (WS_TABSTOP);
}
SetWindowLongPtr(hwnd, GWL_STYLE, (LONG_PTR)s);
}
}
};
property <int> Mousehover
{
Get(int)
{
return intMouseHover;
},
Set(int mousehover)
{
intMouseHover = mousehover;
}
};
};
when i do:
why the Mousehover and TabStop aren't showed in Intelligence List?(when we write the dot, a list is showed)
why the Mousehover and TabStop aren't showed in Intelligence List?(when we write the dot, a list is showed)
Is your comma-notation and functions without retyrn type proper C++ syntax? I am guessing this would confuse C::B
you have
property <int> Mousehover
{
Get(int)
{
return intMouseHover;
},
Set(int mousehover)
{
intMouseHover = mousehover;
}
};
I would guess you need something like (observe comma removed, return types added)
property <int> Mousehover
{
int Get()
{
return intMouseHover;
}
void Set(int mousehover)
{
intMouseHover = mousehover;
}
};
if you can give me the right macro.. i accept ;)
heres the Get and Set macros:
#define Get(x) [this]()->x
#define Set(...) [this](__VA_ARGS__)->void