void InterfacePointerValue::put(const std::string& name, Value* value, int attributes) { InterfacePrototypeValue* proto = static_cast<InterfacePrototypeValue*>(prototype); AttributeSetterValue* setter; if (!canPut(name)) { return; } if (hasProperty(name)) { ObjectValue::put(name, value, attributes); } else if ((setter = static_cast<AttributeSetterValue*>(proto->getOpObject(InterfacePrototypeValue::IndexSetter))) && isIndexAccessor(name)) { setter->put(this, name, value); } else if ((setter = static_cast<AttributeSetterValue*>(proto->getOpObject(InterfacePrototypeValue::NameSetter)))) { setter->put(this, name, value); } else { ObjectValue::put(name, value, attributes); } }
bool othello::canMove(int type) { for(int i=0; i<8; i++) { for(int j=0; j<8; j++) { if(canPut(i,j,type)) return 1; } } return 0; }
void dfs(int n, int k, vector<int> &cols) { if (k == n) { sum++; return; } for (int i = 0; i < n; i++) { if (!canPut(k, i, cols)) { continue; } cols[k] = i; dfs(n, k + 1, cols); } }
void Sudoku::solve() { int spot[] = {0, 0}; if (!nextEmpty(spot)) { return; } for (int i=1; i<10; i++) { if (canPut(spot, i)) { board[spot[0]][spot[1]] = i; solve(); int _[] = {0, 0}; if (!nextEmpty(_)) { return; } } } board[spot[0]][spot[1]] = 0; // solution not found, backtrack }
// ECMA 8.6.2.2 EXPORT void JSObject::put(ExecState* exec, const Identifier &propertyName, JSValue *value, int attr) { assert(value); // non-standard netscape extension if (propertyName == exec->propertyNames().underscoreProto) { JSObject* proto = value->getObject(); while (proto) { if (proto == this) throwError(exec, GeneralError, "cyclic __proto__ value"); proto = proto->prototype() ? proto->prototype()->getObject() : 0; } setPrototype(value); return; } /* TODO: check for write permissions directly w/o this call */ /* Doesn't look very easy with the PropertyMap API - David */ // putValue() is used for JS assignemnts. It passes no attribute. // Assume that a C++ implementation knows what it is doing // and let it override the canPut() check. if ((attr == None || attr == DontDelete) && !canPut(exec,propertyName)) { #ifdef KJS_VERBOSE fprintf( stderr, "WARNING: canPut %s said NO\n", propertyName.ascii() ); #endif return; } // Check if there are any setters or getters in the prototype chain JSObject *obj = this; bool hasGettersOrSetters = false; while (true) { if (obj->_prop.hasGetterSetterProperties()) { hasGettersOrSetters = true; break; } if (!obj->_proto->isObject()) break; obj = static_cast<JSObject *>(obj->_proto); } if (hasGettersOrSetters) { obj = this; while (true) { unsigned attributes; if (JSValue *gs = obj->_prop.get(propertyName, attributes)) { if (attributes & GetterSetter) { JSObject *setterFunc = static_cast<GetterSetterImp *>(gs)->getSetter(); if (!setterFunc) { throwSetterError(exec); return; } List args; args.append(value); setterFunc->call(exec, this, args); return; } else { // If there's an existing property on the object or one of its // prototype it should be replaced, so we just break here. break; } } if (!obj->_proto->isObject()) break; obj = static_cast<JSObject *>(obj->_proto); } } _prop.put(propertyName,value,attr); }