libcommonc++  0.7
JavaScope.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_JavaScope_hxx
24 #define __ccxx_JavaScope_hxx
25 
26 #include <commonc++/Common.h++>
28 
29 namespace ccxx {
30 
54 class /* COMMONCPP_API */ JavaScope
55 {
56  public:
57 
62  JavaScope(JavaContext& context, int capacity)
63  : _context(context),
64  _once(true)
65  {
66  _context.pushLocalFrame(capacity);
67  }
68 
71  {
72  _context.popLocalFrame();
73  }
74 
76  inline bool testOnce()
77  { bool f = _once; _once = false; return(f); }
80  private:
81 
82  JavaContext& _context;
83  bool _once;
84 
85  CCXX_COPY_DECLS(JavaScope);
86 }
87 
88 } // namespace ccxx
89 
96 #ifdef java_scoped
97 #undef java_scoped
98 #endif java_scoped
99 
100 #if (defined CCXX_OS_WINDOWS) && (defined _MSC_VER) && (_MSC_VER < 1400)
101 
102 #define java_scoped(JC, CAP) \
103  for(JavaScope JC ## _scope(JC, CAP); JC ## _scope.testOnce();)
104 
105 #else
106 
107 #define java_scoped(JC, CAP) \
108  for(JavaScope CCXX_OS_UNIQUE_VARNAME(JC, __LINE__, scope)(JC, CAP); \
109  CCXX_OS_UNIQUE_VARNAME(JC, __LINE__, scope).testOnce();)
110 
111 #endif
112 
113 #endif // __ccxx_JavaScope_hxx
JavaScope(JavaContext &context, int capacity)
Construct a new JavaScope for the given JavaContext and local reference capacity. ...
Definition: JavaScope.h++:62
~JavaScope()
Destructor.
Definition: JavaScope.h++:70
void popLocalFrame()
Destroy the topmost local reference frame.
Definition: JavaContext.c++:1827
When the Invocation Interface is being used (that is, when a C++ program calls into Java code)...
Definition: JavaContext.h++:67
void pushLocalFrame(uint_t capacity=8)
Create a new local reference frame.
Definition: JavaContext.c++:1816
Definition: AllocationMap.c++:25
A convenience class for creating lexical Java scopes in native code.
Definition: JavaScope.h++:54