109 lines
1.9 KiB
C++
109 lines
1.9 KiB
C++
#ifndef _TEST_ATOM_HPP_
|
|
#define _TEST_ATOM_HPP_
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#endif
|
|
|
|
class Atom
|
|
{
|
|
public:
|
|
Atom(void);
|
|
virtual ~Atom();
|
|
BOOL operator==(const Atom &someAtom)const;
|
|
BOOL create(const String &strAtomName);
|
|
BOOL assume(const String &strAtomName);
|
|
BOOL getName(String &strAtomName)const;
|
|
BOOL isOkay(void)const;
|
|
void destroy(void);
|
|
private:
|
|
enum Disposition{Assume,Destroy,None};
|
|
enum {MaxString=256};
|
|
Atom(const Atom &someAtom);
|
|
Atom &operator=(const Atom &someAtom);
|
|
Disposition disposition(void)const;
|
|
void disposition(Disposition disposition);
|
|
|
|
ATOM mhAtom;
|
|
Disposition mDisposition;
|
|
};
|
|
|
|
inline
|
|
Atom::Atom(void)
|
|
: mhAtom(0), mDisposition(None)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Atom::Atom(const Atom &someAtom)
|
|
{ // private implementation
|
|
*this=someAtom;
|
|
}
|
|
|
|
inline
|
|
Atom::~Atom()
|
|
{
|
|
destroy();
|
|
}
|
|
|
|
inline
|
|
Atom &Atom::operator=(const Atom &someAtom)
|
|
{ // private implementation
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
BOOL Atom::operator==(const Atom &someAtom)const
|
|
{
|
|
return mhAtom==someAtom.mhAtom;
|
|
}
|
|
|
|
inline
|
|
BOOL Atom::create(const String &strAtomName)
|
|
{
|
|
destroy();
|
|
mhAtom=::GlobalAddAtom((LPSTR)(String&)strAtomName);
|
|
mDisposition=Destroy;
|
|
return isOkay();
|
|
}
|
|
|
|
inline
|
|
BOOL Atom::assume(const String &strAtomName)
|
|
{
|
|
destroy();
|
|
if(strAtomName.isNull())return FALSE;
|
|
mhAtom=::GlobalFindAtom((LPSTR)(String&)strAtomName);
|
|
if(!isOkay())return FALSE;
|
|
mDisposition=Assume;
|
|
return TRUE;
|
|
}
|
|
|
|
inline
|
|
void Atom::destroy(void)
|
|
{
|
|
if(!isOkay())return;
|
|
::GlobalDeleteAtom(mhAtom);
|
|
mhAtom=0;
|
|
mDisposition=None;
|
|
}
|
|
|
|
inline
|
|
BOOL Atom::getName(String &strAtomName)const
|
|
{
|
|
String varAtomName;
|
|
|
|
if(!isOkay())return FALSE;
|
|
varAtomName.reserve(MaxString);
|
|
if(!::GlobalGetAtomName(mhAtom,varAtomName,MaxString))return FALSE;
|
|
strAtomName=varAtomName;
|
|
return !(strAtomName.isNull());
|
|
}
|
|
|
|
inline
|
|
BOOL Atom::isOkay(void)const
|
|
{
|
|
return (mhAtom?TRUE:FALSE);
|
|
}
|
|
#endif |