File: crobject.cpp

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (128 lines) | stat: -rw-r--r-- 3,317 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
   FALCON - The Falcon Programming Language.
   FILE: crobject.cpp

   Core object implementation
   -------------------------------------------------------------------
   Author: Giancarlo Niccolai
   Begin: dom dic 5 2004

   -------------------------------------------------------------------
   (C) Copyright 2004: the FALCON developers (see list in AUTHORS file)

   See LICENSE file for licensing details.
*/

/** \file
   Core object implementation.
*/

#include <falcon/vm.h>
#include <falcon/crobject.h>
#include <falcon/stream.h>

namespace Falcon {

CRObject::CRObject( const CoreClass *generator,  bool bDeserial ):
   CacheObject( generator, bDeserial )
{}

CRObject::CRObject( const CRObject &other ):
   CacheObject( other )
{}

bool CRObject::setProperty( const String &propName, const Item &value )
{
   register uint32 pos;
   const PropertyTable &pt = m_generatedBy->properties();
   if ( pt.findKey( propName, pos ) )
   {
      // to be optimized
      const PropertyTable &pt = m_generatedBy->properties();

      //Ok, we found the property, but what should we do with that?
      const PropEntry &entry = pt.getEntry( pos );
   
      // can we write it?
      if ( entry.m_bReadOnly ) {
         throw new AccessError( ErrorParam( e_prop_ro, __LINE__ ).extra( propName ) );
      }
   
      if ( entry.m_eReflectMode != e_reflectNone )
      {
         fassert( m_user_data != 0 || entry.m_eReflectMode == e_reflectSetGet );
         entry.reflectTo( this, m_user_data, value );
         // remember to cache the value.
      }
   
      if ( value.isReference() )
         m_cache[ pos ] = value;
      else
         *m_cache[ pos ].dereference() = value;
         
      return true;
   }

   return false;
}


bool CRObject::getProperty( const String &propName, Item &ret ) const
{
   fassert( m_generatedBy != 0 );

   register uint32 pos;
   const PropertyTable &pt = m_generatedBy->properties();

   if ( pt.findKey( propName, pos ) )
   {
      Item &cached = *m_cache[pos].dereference();
      const PropEntry &entry = pt.getEntry(pos);
      if ( entry.m_eReflectMode != e_reflectNone )
      {
         fassert( m_user_data != 0 || entry.m_eReflectMode == e_reflectSetGet );
         // this code allows to modify our cached value.
         entry.reflectFrom( const_cast<CRObject*>( this ), m_user_data, cached );
      }

      ret = cached;
      
      // already assigned, if possible
      return true;
   }

   return false;
}

CRObject *CRObject::clone() const
{
   return new CRObject( *this );
}

//============================================
CoreObject* CROpaqueFactory( const CoreClass *cls, void *user_data, bool bDeserial )
{
   CRObject* cro = new CRObject( cls, bDeserial );
   cro->setUserData( user_data );
   return cro;
}

CoreObject* CRFalconFactory( const CoreClass *cls, void *user_data, bool bDeserial )
{
   CRObject* cro = new CRObject( cls, bDeserial );
   if( user_data != 0 )
      cro->setUserData( static_cast<FalconData*>(user_data) );
   return cro;
}

CoreObject* CRSequenceFactory( const CoreClass *cls, void *user_data, bool bDeserial )
{
   CRObject* cro = new CRObject( cls, bDeserial );
   if( user_data != 0 )
      cro->setUserData( static_cast<Sequence*>(user_data) );
   return cro;
}

} // namespace Falcon

/* end of crobject.cpp */