Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sciter 4.4.7.0 #299

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Go bindings for Sciter

[![Build status](https://ci.appveyor.com/api/projects/status/rphv883klffw9em9/branch/master?svg=true)](https://ci.appveyor.com/project/pravic/go-sciter)
[![Build Status](https://img.shields.io/travis/sciter-sdk/go-sciter/master.svg)](https://travis-ci.org/sciter-sdk/go-sciter)
[![AppVeyor status](https://ci.appveyor.com/api/projects/status/rphv883klffw9em9/branch/master?svg=true)](https://ci.appveyor.com/project/pravic/go-sciter)
[![Travis Status](https://travis-ci.com/sciter-sdk/go-sciter.svg?branch=master)](https://travis-ci.com/sciter-sdk/go-sciter)
[![License](https://img.shields.io/github/license/sciter-sdk/go-sciter.svg)](https://github.com/sciter-sdk/go-sciter)
[![Join the forums at https://sciter.com/forums](https://img.shields.io/badge/forum-sciter.com-orange.svg)](https://sciter.com/forums)

Expand Down
257 changes: 197 additions & 60 deletions include/sciter-om-def.h

Large diffs are not rendered by default.

69 changes: 49 additions & 20 deletions include/sciter-om.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
#pragma once

#include <string.h>
#include <assert.h>
#ifndef __SCITER_OM_H__
#define __SCITER_OM_H__


struct som_passport_t;
struct som_asset_class_t;

typedef UINT64 som_atom_t;


struct som_asset_class_t;

typedef struct som_asset_t {
struct som_asset_class_t* isa;
} som_asset_t;

struct som_asset_class_t {
typedef struct som_asset_class_t {
long(*asset_add_ref)(som_asset_t* thing);
long(*asset_release)(som_asset_t* thing);
long(*asset_get_interface)(som_asset_t* thing, const char* name, void** out);
struct som_passport_t* (*asset_get_passport)(som_asset_t* thing);
};
} som_asset_class_t;


inline som_asset_class_t* som_asset_get_class(const som_asset_t* pass)
{
return pass ? pass->isa : 0;
}

som_atom_t SCAPI SciterAtomValue(const char* name);

#ifdef CPP11

#include <cstring>
#include <cassert>
#include <atomic>

namespace sciter {

class atom {
som_atom_t _atom;
public:
atom(const char* name) { _atom = SciterAtomValue(name); }
atom(const atom& other) { _atom = other._atom; }
operator som_atom_t() const { return _atom; }
};

namespace om {

template <class R> class hasset;

// implementation of som_asset_t ISA
// note: does not define asset_add_ref()/asset_release() as they shall be defined in specializations
template <class A>
class iasset : public som_asset_t
{
Expand Down Expand Up @@ -70,7 +88,6 @@ namespace sciter {
//template<class C> hasset<C> interface_of() { hasset<C> p; get_interface(C::interface_name(), p.target()); return p; }
};


inline long asset_add_ref(som_asset_t *ptr) {
assert(ptr);
assert(ptr->isa);
Expand All @@ -97,8 +114,13 @@ namespace sciter {
return ptr->isa->asset_get_passport(ptr);
}

inline som_asset_class_t* asset_get_class(som_asset_t *ptr) {
assert(ptr);
return ptr->isa;
}

//hasset - yet another shared_ptr
// R here is something derived from the iasset (om::iasset) above
// R here is an entity derived from som_asset_t
template <class R> class hasset
{
protected:
Expand All @@ -108,10 +130,10 @@ namespace sciter {
typedef R asset_t;

hasset() :p(nullptr) {}
hasset(R* lp) :p(nullptr) { if (lp) (p = lp)->asset_add_ref(); }
hasset(const hasset<R>& cp) :p(nullptr) { if (cp.p) (p = cp.p)->asset_add_ref(); }
hasset(R* lp) :p(nullptr) { if (lp) asset_add_ref(p = lp); }
hasset(const hasset<R>& cp) :p(nullptr) { if (cp.p) asset_add_ref(p = cp.p); }

~hasset() { if (p) p->asset_release(); }
~hasset() { if (p) asset_release(p); }
operator R*() const { return p; }
R* operator->() const { assert(p != 0); return p; }

Expand All @@ -121,7 +143,7 @@ namespace sciter {
bool operator==(R* pR) const { return p == pR; }

// release the interface and set it to NULL
void release() { if (p) { R* pt = p; p = 0; pt->asset_release(); } }
void release() { if (p) { R* pt = p; p = 0; asset_release(pt); } }

// attach to an existing interface (does not AddRef)
void attach(R* p2) { asset_release(p); p = p2; }
Expand All @@ -130,8 +152,8 @@ namespace sciter {

static R* assign(R* &pp, R* lp)
{
if (lp != 0) lp->asset_add_ref();
if (pp) pp->asset_release();
if (lp != 0) asset_add_ref(lp);
if (pp) asset_release(pp);
pp = lp;
return lp;
}
Expand All @@ -143,10 +165,8 @@ namespace sciter {

};


// intrusive add_ref/release counter

template<class C>
// reference counted asset, uses intrusive add_ref/release counter
template<class C>
class asset : public iasset<asset<C>>
{
std::atomic<long> _ref_cntr;
Expand Down Expand Up @@ -179,11 +199,20 @@ namespace sciter {
delete static_cast<C*>(this);
}
};
}


template <class AT>
inline AT* value::get_asset() const {
som_asset_t* pass = get_asset();
if (pass && (som_asset_get_class(pass) == AT::get_asset_class()))
return static_cast<AT*>(pass);
return nullptr;
}

}

#endif

#include "sciter-om-def.h"

#endif
Loading