미디어 위키 문법 정리

simuruk wiki

하하호호히히
112233
!하하!호호!히히|
|11|22|33|

접기

접기

<div class="mw-collapsible mw-collapsed">
접기
</div>

코드블럭

1 코드

이미지

java-collections2.jpg

[[File:java-collections2.jpg|800px]]

페이지 추가

멀티스레드 개발에서 일관성을 보장해주는 방식

  • 생성자 막기
  • 소멸자 막기
  • getter
  • multithread
// C++
Foo* Foo::Instance() {
  if(pinstance == nullptr) {
    lock_guard<mutex> lock(m_);
    if(pinstance == nullptr) {
        pinstance = new Foo();
    }
  }
  return pinstance;
}
// JAVA
public static synchronized singleton getInstance () {
    if (instance == null)
        instance = new ThreadSafeInitalization();
    return instance;
}

접기 1. 주소 값을 이용한 방식

 
class yh_singleton
{
public:
	static yh_singleton&amp; getInstanse(){
		static yh_singleton instance;
		return instance;
	};
	int num;
private:
	yh_singleton(){};
	yh_singleton(const yh_singleton&amp; other);
	yh_singleton&amp; operator=(yh_singleton&amp; cls);
	~yh_singleton(){};
};

yh_singleton&amp; yh= yh_singleton::getInstanse();
yh.num= 4;

2. 포인터를 이용한 방식

 
class yh_singleton
{
public:
	static yh_singleton* getInstanse(){
		static yh_singleton instance;
		return &amp;instance;
	};
	int num;
private:
	yh_singleton(){};
	yh_singleton(const yh_singleton&amp; other);
	yh_singleton&amp; operator=(yh_singleton&amp; cls);
	~yh_singleton(){};
};

yh_singleton* yh= yh_singleton::getInstanse();
yh->;num= 4;

3. 템플릿 싱글톤

 
template &lt;typename T&gt;
class yh_singleton
{
public:
	static T* getInstance()
	{
		if (instance == NULL)
			instance = new T;
		return instance;
	};

	static void destroyInstance()
	{
		if (instance)
		{
			delete instance;
			instance = NULL;
		}
	};
private:
	static T* instance;
protected:
	yh_singleton(const yh_singleton&amp; other);
	yh_singleton&amp; operator=(yh_singleton&amp; cls);
	yh_singleton();
	virtual ~yh_singleton(){};
};
template &lt;typename T&gt;T * yh_singleton&lt;T&gt;::instance = NULL;

class ojectA : public yh_singleton&lt;ojectA&gt;
{
public:
	ojectA();
	~ojectA();

	int a;
};
{{:design pattern singleton}}

git 스니펫

https://github.com/yu-young-hoon/shell-util-script.git/blob/master/applescript-airpods-onoff.sh

#!/usr/bin/osascript
set bluetoothName to "유영훈의 AirPods"

activate application "SystemUIServer"
tell application "System Events"
	tell process "SystemUIServer"
		set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
		tell btMenu
			click
			tell (menu item bluetoothName of menu 1)
				click
				if exists menu item "연결" of menu 1 then
					click menu item "연결" of menu 1
					display notification "에어팟 연결" with title "Toggle AirPods"
				else if exists menu item "연결 해제" of menu 1 then
					click menu item "연결 해제" of menu 1
					display notification "에어팟 종료" with title "Toggle AirPods"
				else
					click btMenu -- Close main BT drop down if Connect wasn't present
					return "Airpods were not found, try manually pairing them again!"
				end if
			end tell
		end tell
	end tell
end tell
{{#snippet:
repository=https://github.com/yu-young-hoon/shell-util-script.git|
filename=applescript-airpods-onoff.sh|
branch=master|
startline=1|
endline=99}}